Cur Dir Quiz?
> But then my file dialog would need to keep a dynamic list of the
> last-used directory on each drive. I doubt that the Common Dialog
> does that, for example – how could it keep a persistent list?
> There must be another way.
Oops, I don't think we're on the same wavelength here. Let's start from the
beginning.
Say the current drive is D: and the current directory is the root "\".
Step 1: First call GetCurrentDirectory() to find out where you are NOW.
Display this information to the user. You will display "D:\".
Step 2: Now you want to fill up one dialog listbox with all the files there. Do
this with the mask "*.*" with no drive or path specifier. The same calls to
FindFirstFile and FindNextFile give you all the subdirectories, which you can
drop into another listbox (I don't remember, but you may need to add ".."
yourself.)
Step 3A: Now say the user clicks on the SAMPLE directory in the subdirectory
list box. Now, you call SetCurrentDirectory("SAMPLE"), and the current
directory becomes D:\SAMPLE. Just go to back to step 1.
Step 3B: Say the user clicks drive E: from your drives listbox instead. Just
call SetCurrentDirectory("E:") and go to step 1 again. Current directory will
probably become E:\.
Step 4: If the user now clicks D:, just call SetCurrentDirectory("D:") and go
to step 1 again. I am pretty sure, that because you were in the SAMPLE
subdirectory LAST time you were on drive D:, you will be there again now. There
is no need for YOU to remember in your code what the proper directory is for
each drive letter. The secret is to use RELATIVE paths for the calls to
SetCurrentDirectory(), especially when switching from drive to drive. You may
need to use "D:." rather than just "D:".
My last message may have described this poorly in sake of brevity. I may have
been confused with OS/2, which provides separate, handy, GetCurrentDrive and
SetCurrentDrive functions, allowing you to move the current directory for any
drive without actually <going there> (Like typing 'cd d:\sample' on the
command line while you are still on drive C:.)
If I have misrepresented how SetCurrentDirectory() works, please jump in
anyone!
Stan Pensak
Read action !re 79905
Enter reply. (/EXIT when done)
1: You have described exactly what I tried. However, specifying
2: either "DC:D:" or "D:." does not give the desired result of
3: "remembering" the current directory on the drive. It
4: really changes to root every time, as far as I can tell.
5: (Trying "D:\" does change to root, too. 🙂 )
6: /post
Message # 79929 posted