Open Folder Command in VB6 - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Open Folder Command in VB6

I use VB6 and for the life of me I cannot figure out what code to use which would allow me to simply open a folder so that I may select from several Word Documents. Please excuse my ignorance, I'm a lawyer not a Computer Expert! Thanks!

Bob Nichols

Comments

  • PsightoplazmPsightoplazm Posts: 332Member ✭✭
    We understand that it is hard not understanding the ways of the force, but in time your powers will grow :P

    To open a folder in the "Explorer" you have to send it to the "Explorer" as you would a file to any other program. So assuming you know the location of the windows explorer executable...


    you can use the SHELL command... Like so...

    Shell("Explorer.exe C:Windows")

    And what that does is sends "C:Windows" to the explorer and a window will open with the contents of the Windows folder on the C drive.

    The reason you don't normaly need to type in C:WindowsSystem32Explorer.exe is because windows has a setting that says it is assumed that if you don't type in a path for the executable you are trying to use a system executable ( or a file located at a default location)...

    I hope I wasn't confusing with that, if so let me know and I'll whip out some more detail.

    :)
    ><//~Psightoplasm`~

  • WaltPWaltP Posts: 335Member
    : I use VB6 and for the life of me I cannot figure out what code to use which would allow me to simply open a folder so that I may select from several Word Documents. Please excuse my ignorance, I'm a lawyer not a Computer Expert! Thanks!
    :
    : Bob Nichols
    :
    Open the tools/components list (ctrl-T) and choose the "Microsoft Common Dialog Control". The help system will take you the rest of the way.


    ----------------
    Walt


  • BobNicholsBobNichols Posts: 2Member
    : We understand that it is hard not understanding the ways of the force, but in time your powers will grow :P
    :
    : To open a folder in the "Explorer" you have to send it to the "Explorer" as you would a file to any other program. So assuming you know the location of the windows explorer executable...
    :
    :
    : you can use the SHELL command... Like so...
    :
    : Shell("Explorer.exe C:Windows")
    :
    : And what that does is sends "C:Windows" to the explorer and a window will open with the contents of the Windows folder on the C drive.
    :
    : The reason you don't normaly need to type in C:WindowsSystem32Explorer.exe is because windows has a setting that says it is assumed that if you don't type in a path for the executable you are trying to use a system executable ( or a file located at a default location)...
    :
    : I hope I wasn't confusing with that, if so let me know and I'll whip out some more detail.
    :
    : :)
    : ><//~Psightoplasm`~
    :
    : Thank you very much. One more question! The Folder I seek to open is a varible with the name of "FolderName" (I'm not that imaginative). How would that fit into Shell("Explorer.exe C:Windows"), I cannot get it to work! Again, thank you! Bob

  • PsightoplazmPsightoplazm Posts: 332Member ✭✭
    Is it named FolderName or Folder Name, because if there are any spaces there will be a problem because shell will want the DOS version of your path.
    If there are any folders with spaces in the names then it will not work either....

    THere is an API that will convert your path name into dos, but you can figure it out too... basically nothing can have spaces and I think the maximum letters it can have per folder is 11... so if a folders name is blahblahblah then the dos name of it would be blahblahb~1

    Or if ther was another folder named blahblahblahblah then it might be blahblahb~2 or 3 or 4 or whatever...

    Otherwise I don't remember what the API was, maybe someone reading this knows.

    ><//~Psightoplasm`~

  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : Is it named FolderName or Folder Name, because if there are any spaces there will be a problem because shell will want the DOS version of your path.
    : If there are any folders with spaces in the names then it will not work either....
    :
    : THere is an API that will convert your path name into dos, but you can figure it out too... basically nothing can have spaces and I think the maximum letters it can have per folder is 11... so if a folders name is blahblahblah then the dos name of it would be blahblahb~1
    :
    : Or if ther was another folder named blahblahblahblah then it might be blahblahb~2 or 3 or 4 or whatever...
    :
    : Otherwise I don't remember what the API was, maybe someone reading this knows.
    :
    : ><//~Psightoplasm`~
    :
    :

    Shell doesn't care if you pass the DOS or LFN; neither does Explorer. However, if it contains spaces, it needs to be surrounded with quotes.

    Shell """C:Some path with spacesFilename with spaces.exe"" " & """" FolderName & """", vbNormalFocus

    I think I have the right count of " in there. Basically, the first " is a "flag" to VB for a string const. After that, a " could be the end of the string or it could be an embedded ". If there is another " after this one, then it's an embedded "; otherwise it's the end of the string.

    Now, some explorer flags you may be interested in:

    /e - use explorer view (includes folder tree, acts a little different)
    /mc - My Computer view (no folder tree), default.
    /root - Explorer acts as though there are no folders above the one you've selected. Can cause performance issues in some cases (I'm not sure when, but Explorer sometimes take a long time (3-10 seconds) to display a folder).
    /select - opens Explorer to the appropriate folder and selects the item in that folder.

    Seperate parameters with commas, [italic]no spaces[/italic]!

    So to open C:My Documents in a rooted view and with the folder tree:

    Explorer /e,/root,"C:My Documents"

    To pass that to Shell:

    Shell "Explorer.exe /e,/root,""" & FolderName & """", vbNormalFocus

    Be prepared to experiment a bit, Explorer is [italic]very[/italic] picky about the order of the commandline. I think I have it shown correctly here, but I could be mistaken.

    Hope this helps!
Sign In or Register to comment.