06-01-2018 08:09 AM
Hello.So I noticed that every time I use the "file Dialog VI" it always opens with the last directory that I accessed.I want to be able to suggest to the user the last file/s used by going into the last directory used to choose a file and then suggesting to the user the files of a given type from this directory.Does anyone know a way to find path to the last directory accessed with file Dialog?
06-01-2018 08:24 AM
Why not just store the last directory that was accessed?
06-01-2018 08:27 AM
Thank you! I could but I was curious if there's a more direct solution..
06-01-2018 08:39 AM
Actually I don't think you can get more direct than that. It's a wire. Now maybe you bundle this value into a cluster but it's still stored in a wire or a shift register. Or, if the value is needed in other parts of your code, maybe you store it in some sort of global variable. I don't know why a specific VI to get this value is needed because it would do exactly what I describe above.
06-01-2018 09:06 AM
It's because if am to store it the way you suggest,then i'll have to store it in a file or registry for the next time I run my application.But somehow every time i run a file Dialog VI,it always opens with that last directory i used from the previous session.I wonder how it does that!
06-01-2018 09:24 AM
It's probably stored in a file or in the registry.
06-01-2018 12:21 PM
un-initialized shift register?
06-05-2018 04:04 AM
Thank zwired..sorry for the late response..I am failing to understand how to modify you solution to fit to my situation..Even without the un-intialized shift register,File Dialog box will still open with the last directory view in the file dialog box.You can try it out,run the File dialog and select a file,the next time the File Dialog box opens up it will open in the last viewed directory..what i want is to get the last viewed directory,without opening up the File dialog box again.. I hope i understood you.
06-05-2018 10:44 AM
It looks like the last accessed directory is stored in the registry. However it is stored in binary format and will take some work to get it in a readable format. See here for details. Not very direct, as you requested. I think you're better off just storing it in a file yourself, but it might be a fun exercise to figure it out.
06-06-2018 06:19 AM - edited 06-06-2018 06:20 AM
There are various elements which are involved in this. The first is an applications CWD (current working directory). This is a DOS process setting that has been taken over into Windows for compatibility reasons. It doesn't make to much sense for GUI applications but is essential for command line tools to work like they did in DOS. When a process starts the CWD is set to the directory the process executable was started from.
The Windows File Dialog uses this to intialize the start directory where it should open if the application doesn't pass in an specific path to start at. When you select a file or directory in the file dialog and press OK (Open/Save) then Windows will update the process CWD to the directory the dialog was in at the moment you pressed the OK button.
This path can be retrieved with the Windows API GetCurrentDirectoryA() and changed with SetCurrentDirectoryA() but the concept is pretty flawed as anybody could call that function at any point and the file dialog will change the CWD too each time it is dismissed. So hoping to get a reliable location with this is simply playing roulette.
Then there is the MRU (Most Recently Used) locations which is what the last post from aputman is mostly referencing to. This is not a Windows API feature but rather a .Net addition to the file dialog so not available for the file dialog in LabVIEW.