Results 1 to 6 of 6

Thread: [RESOLVED] OpenFileDialog RestoreDirectory

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    15

    Resolved [RESOLVED] OpenFileDialog RestoreDirectory

    hi
    sorry for my English
    when i use open file dialog , after file selection , my current Directory is changing to selected file Directory .
    as i know there is a option in .net for this , but what can i do for vb6?

    i need my current Directory because i use many cmd commands in that
    also i try saving current Directory az string , but not works

    befor:
    C:\Users\win\Desktop\New foldser>
    after file dialog:
    D:\test\tre>
    Last edited by astarali; Oct 4th, 2017 at 05:52 PM.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: OpenFileDialog RestoreDirectory

    Read OPENFILENAME structure which is used internally. Read the part about lpstrInitialDir.

    lpstrInitialDir
    Type: LPCTSTR

    The initial directory. The algorithm for selecting the initial directory varies on different platforms.

    Windows 7:
    1.If lpstrInitialDir has the same value as was passed the first time the application used an Open or Save As dialog box, the path most recently selected by the user is used as the initial directory.
    2.Otherwise, if lpstrFile contains a path, that path is the initial directory.
    3.Otherwise, if lpstrInitialDir is not NULL, it specifies the initial directory.
    4.If lpstrInitialDir is NULL and the current directory contains any files of the specified filter types, the initial directory is the current directory.
    5.Otherwise, the initial directory is the personal files directory of the current user.
    6.Otherwise, the initial directory is the Desktop folder.

    Windows 2000/XP/Vista:
    1.If lpstrFile contains a path, that path is the initial directory.
    2.Otherwise, lpstrInitialDir specifies the initial directory.
    3.Otherwise, if the application has used an Open or Save As dialog box in the past, the path most recently used is selected as the initial directory. However, if an application is not run for a long time, its saved selected path is discarded.
    4.If lpstrInitialDir is NULL and the current directory contains any files of the specified filter types, the initial directory is the current directory.
    5.Otherwise, the initial directory is the personal files directory of the current user.
    6.Otherwise, the initial directory is the Desktop folder.

  3. #3
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: OpenFileDialog RestoreDirectory

    If your main concern is - You have a folder that you wish to always be able to go to directly ?
    Then get an additional(better) file manager.
    I would get one with Tabs, that has the ability to lock one of the tabs into your favorite folder.
    XYPlorer has that ability.
    There is/was a free version - XYPlorerFree that also has most of the features of the Pro version.
    I believe PortableApps has it as part of their suite. If there is too much baggage for you in PortableAppls then there is -
    http://www.softpedia.com/get/File-ma...orerFree.shtml
    http://www.softpedia.com/get/PORTABL...orerFree.shtml
    XYPlorer requires no installation (the same god I, and Elroy, worship)

    HTH,
    Rob

  4. #4
    gibra
    Guest

    Re: OpenFileDialog RestoreDirectory

    I do not know if I understood well, but you can

    - Use CurDir to store your current directory:
    i.e. declare a public variable in a BAS module
    Code:
    Public gsMyCommandDir As String
    next, when program start store value:
    Code:
    gsMyCommandDir = CurDir() ' get current directory
    - use ChDir to 'return' to your default directory before launch CMD.EXE
    Code:
    ChDir gsMyCommandDir

  5. #5
    Hyperactive Member
    Join Date
    Aug 2017
    Posts
    380

    Re: OpenFileDialog RestoreDirectory

    If you're using the CommonDialog control that came with VB6, it has a flag that will prevent your process' current directory from changing every time you select a file:

    cdlOFNNoChangeDir &H8 Forces the dialog box to set the current directory to what it was when the dialog box was opened.
    If you're calling the GetOpenFileName API directly, the equivalent constant is:

    OFN_NOCHANGEDIR
    0x00000008
    Restores the current directory to its original value if the user changed the directory while searching for files.
    Note that a process' current directory is different from the Open dialog's initial directory setting.
    Last edited by Victor Bravo VI; Oct 5th, 2017 at 04:07 AM.

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    15

    Re: OpenFileDialog RestoreDirectory

    Quote Originally Posted by Victor Bravo VI View Post
    If you're using the CommonDialog control that came with VB6, it has a flag that will prevent your process' current directory from changing every time you select a file:

    cdlOFNNoChangeDir &H8 Forces the dialog box to set the current directory to what it was when the dialog box was opened.
    If you're calling the GetOpenFileName API directly, the equivalent constant is:

    OFN_NOCHANGEDIR
    0x00000008
    Restores the current directory to its original value if the user changed the directory while searching for files.
    Note that a process' current directory is different from the Open dialog's initial directory setting.
    Yesss , Very Good , Thanks Man . +rep

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width