LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Default directory in FileSelectPopup

Solved!
Go to solution

The default directory in FileSelectPopup is defined as:

int FileSelectPopup (char defaultDirectory[], …)

defaultDirectory[] : If you enter "", the function uses the current working directory for the initial directory. If the user selects a directory, and the popup is displayed again in the application, the default directory is the user-selected directory.

 

This behavior creates a problem for my application. I need the default directory to always be the one that I specify in the defaultDirectory[], not the one that user selected previously. Is there a way to override the user selected directory and always start the browsing in the specified directory?

0 Kudos
Message 1 of 13
(2,760 Views)

If you actually pass a folder pathname in the parameter the function should always start in that folder, isn't it so?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 13
(2,743 Views)

And I think there is a parameter so that you can restrict the directory change of the user. So user is stuck with the directory that you specify. 

S. Eren BALCI
IMESTEK
0 Kudos
Message 3 of 13
(2,741 Views)

No, I'm seeing a different behavior. I do specify the default directory and I tried to restrict the directory change of this specific instance of FileSelectPopup (this instance is for saving config files that are stored in config directory). But I also have another instance of FileSelectPopup to save data files in the data directory. And whenever I call the FileSelectPopup to store the data file in data directory then next time I call the FileSelectPopup to store the config it starts again in the data directory. So restricting the directory change actually makes it worse because I cannot even change the directory to point to the config directory. If I do not restrict the change I can of course always manually change the directory to config, it's not a big problem, but it's just going to be annoying for the users.

 

Here is an example of the code line that I use (without directory change restriction)

FileSelectPopup (".\\settings", "config.cfg", "*.cfg", "Select file to save settings", VAL_SAVE_BUTTON, 0, 1, 1, 1, pathName);

 

Am I missing something?

0 Kudos
Message 4 of 13
(2,736 Views)

I actually see the opposite: the call with no path inherits the path passed to the other call, while the call with a relative (or absolute) path always starts in the proper folder.

See the attached example.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 5 of 13
(2,710 Views)

Roberto, thanks for your code but I am still seeing the same behavior that I described even with your code. In your example if I copy the Panel.uir to another directory and then select it with either "no path" or "relative path" button then when I press the "relative path" button again it starts in that other directory, not in the \Data directory. 

Could it be something wrong with my computer?

0 Kudos
Message 6 of 13
(2,697 Views)

Now that's weird! I don't understand what can be happening.

What happens if you pass an absolute pathname? I mean something like that:

GetProjectDir (pathName);
MakePathname (pathName, "settings", pathName);
FileSelectPopup (pathName, "config.cfg", "*.cfg", "Select file to save settings", VAL_SAVE_BUTTON, 0, 1, 1, 1, pathName);

This is more or less the same as your relative path approach but with a fully qualified pathname passed to the function instead.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 7 of 13
(2,689 Views)

Yes, the absolute path works fine and always starts from ...\Data:

r = FileSelectPopup ("C:\\Users\\evi75\\Documents\\misc\\FilePaths\\Data", "*.UIR", "User Interface Resources (*.UIR)", "Select a file", VAL_SELECT_BUTTON, 0, 0, 1, 0, file);

 

But the relative path still does not and starts from the last browsed directory:

FileSelectPopup (".\\Data", "*.UIR", "User Interface Resources (*.UIR)", "Select a file", VAL_SELECT_BUTTON, 0, 0, 1, 0, file);

 

I guess I can try to create a string with an absolute path by concatenating the proj directory and the relative path. Is there a function to get the proj directory?

0 Kudos
Message 8 of 13
(2,674 Views)
Solution
Accepted by topic author eno7538

OK, I found it: GetProjectDir (char directoryName[]);

So this workaround works fine now, thanks for the help!

 

char directoryName[250];
GetProjectDir(directoryName);
strcat(directoryName, ".\\Data");
r = FileSelectPopup (directoryName, "*.UIR", "User Interface Resources (*.UIR)", "Select a file", VAL_SELECT_BUTTON, 0, 0, 1, 0, file);

0 Kudos
Message 9 of 13
(2,668 Views)

I've seen the same issue as @eno7538 some weeks ago and I wonder if the behavior depends on the CVI version.

Which version have @eno7538 and @RobertoBozzolo been using?

Vix
-------------------------------------------
In claris non fit interpretatio

-------------------------------------------
Using LV from 7
Using LW/CVI from 6.0
0 Kudos
Message 10 of 13
(2,629 Views)