Discussion:
How to determine if the directory path is valid to create?
(too old to reply)
walle
2005-11-21 10:11:36 UTC
Permalink
Hi!
In my program the user is able to make a name of their current profile. After the user has entered at profilename the program creates a directory to store log-files and datafiles for this profile there. But i ran in to problems when one of my users tried to create a profile ending with "." (dot character). I then tested the "new directory" function and realized that it returns an errorcode 1 when i make a directory like "c:\temp\testdir."
The user is not aware that his profile is stored under a directory and he writes the name in a string control.
It's allowed to use dots inside a name, but not in the end. I tried the "not a path" function... but it doesen't work.
By the way.... I'm able to create a folder in windows explorer with a dot at the end.... but it renames it automatically and removes the dot.
 
My question is!
Is there any good solution in checking if a string/path is built up with legal characters ?
I could restrict the use of certain characters... but . is allowed inside the name... but not in the end ? hmmm......
 
Best Regards
Marcus
devchander
2005-11-21 10:11:38 UTC
Permalink
Hi Marcus,
Look at attached VI
After determining If the 'last string' of the file name is valid or not for windows folders, create that file.
If not valid,  pop up a msg telling this file name is not valid
regards
Dev
 


file name.vi:
http://forums.ni.com/attachments/ni/170/152810/1/file name.vi
walle
2005-11-21 12:10:47 UTC
Permalink
Ok, but what are the characters that is not valid for directories in windows ?
And your example only checks the last value in the path.
Would be great to be able to check the whole path if it's correct, then i'd could add a match string for invalid characters inside the path also....
Windows have certain characters not supported in paths, but "." is not one of them....i think.
There seems to be different invalid characters depending on if they are inside the path or at the end ?
I thought there might be some good function already in labview to check for valid filenames....
Anyone knows exactly what characters are valid to use and where?
 
Again: In explorer your able to create a folder as "c:\temp\test." ... but it actual name becomes "c:\temp\test"
 
Thanks!
/Marcus
walle
2005-11-21 12:10:50 UTC
Permalink
oooh, I just realized that my problem with the "." character as last character disappears if i add an extra whitespace after the "." character.
i.e. "c.\temp\test. "
:smileytongue:
/Marcus
walle
2005-11-21 12:40:32 UTC
Permalink
Hi!
As i described earlier, the user is not aware of that the program is creating a directory. The user only sets a name of it's profile and then the program creates a directory to store certain files for the current profile. And the directory name are set to the profilename...... that's why I'm not able to use the file dialog...
 
/Marcus
becktho
2005-11-21 12:40:33 UTC
Permalink
Just a thought:
Does a user load data which is stored in this directory? If so - what happens, if a user forgets his username or inputs a wrong username, which already exists from another user?
I'd rather implement a simple user administation tool, which only allows certain users to create new users.
Thomas
walle
2005-11-21 12:40:33 UTC
Permalink
No, it's not a user dependant directory/profile. The profile I'm refering to are test-profiles. It's a testapplication and when a user(any user) creates a new profile it stores testdata, current variables, configfiles etc etc in this testprofile-directory. So it's not a windows user profile data or anything.
And as i said, the directory and testfiles/configfiles are made automatically by the application. The user only sets a name for the test (profile).
/Marcus

Continue reading on narkive:
Loading...