LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

find last accessed directory

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?

0 Kudos
Message 1 of 10
(3,066 Views)

Why not just store the last directory that was accessed? 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 10
(3,062 Views)

Thank you! I could but I was curious if there's a more direct solution..

0 Kudos
Message 3 of 10
(3,058 Views)

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.  

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 4 of 10
(3,051 Views)

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!

0 Kudos
Message 5 of 10
(3,039 Views)

It's probably stored in a file or in the registry.  

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 6 of 10
(3,029 Views)

un-initialized shift register?

 

unit.png

0 Kudos
Message 7 of 10
(3,015 Views)

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.

 
0 Kudos
Message 8 of 10
(2,993 Views)

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.  

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 9 of 10
(2,980 Views)

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.

Rolf Kalbermatter
My Blog
0 Kudos
Message 10 of 10
(2,957 Views)