Jump to content

Getting and setting the current directory?


Recommended Posts

I have an app that saves various types of configuration files in xml format. To avoid mixing the different types of configuration files, I have different default directories for each type. For simplicity, I use the Read/Write to XLM File VIs and let the user select the correct file via the automatic dialog box. To get the correct default directory to show up when the dialog box opens I've been trying to use the Get/SetDefaultDirectory functions in kernal32.dll.

post-7603-125363504551_thumb.png

Problem 1: The string returned by the second GetCurrentDirectory call is only showing the drive letter, even though the function is reporting many more characters being written.

Problem 2: The SetCurrentDirectory call reports an error but checking the error code turns up nothing.

Problem 3: The vi occasionally crashes LV. I think I have all my call parameters set up correctly...

Any ideas?

Set Current Directory.vi

Link to comment

Figured it out... sort of. Since these are the Unicode versions of the functions I need to manually convert the strings to 16-bit arrays.

Unfortunately it looks like Labview stores the current directory internally rather than using OS calls. sad.gif No matter how much I change the current directory the XML dialog box defaults to the last directory used from within Labview.

post-7603-125364272016_thumb.png

Edited by Daklu
Link to comment

Unfortunately it looks like Labview stores the current directory internally rather than using OS calls. sad.gif No matter how much I change the current directory the XML dialog box defaults to the last directory used from within Labview.

post-7603-125364272016_thumb.png

Are you using the 'Write to XML File' function from the palette? If you look inside, it calls vi.lib\_oldvers\_oldvers.llb\Open_Create_Replace File.vi with nothing wired to start path.

You might be able to modify or copy 'Write to XML File' and evaluate the path. If it points to an existing folder, pass the folder to the start path and pass a null path for the file. I think this should force the dialog to start where you want it to.

Now if we could just get NI to update their own VIs; to bad they don't have interns and some sort of analyzer that they could use to look for old VIs or functions that need to be updated :rolleyes:

Edited by Phillip Brooks
Link to comment
  • 2 weeks later...

Could you launch your own file browse dialog before the XML function? That way you could hard code your start path etc and simply path the path output from the dialog as the input for your XML functions:

All I can say is... D'oh! frusty.gif

Kudos for you - star.gif

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.