09-19-2008 06:45 AM
I'm trying to check if the path given by the user already exists. In case it doesn't, I'd like to create a folder with name given in the same directory.
Let's say path_1: "C:\folder1" and path_2: "C:\folder2", and suppose that folder1 exists but folder2 doesn't. Then if the path given by the user is the path_1, then ok, nothing happens, but if it is the path_2, then the programm should realize that it doesn't exist in C:\ and should ask you whether you want to create it or not.
I know how to do that for files, but not for folders!
Thanks in advance
09-19-2008 07:17 AM
I can think of at least two options to perform this task:
1. Use SetDir to set the current working directory to the path specified by the user: the function returns -1 if the directory is not found, in which case you can create it.
2. Use MakeDir to directly create the stated directory: if it already exists the function returns -9. You may need to chek other return codes to warn the operator of other errors found.
09-19-2008 08:13 AM
09-19-2008 08:17 AM
You're right: I checked it while I had this function disabled... If you don't want to permanently disable this option, you can embed the instruction between two calls to SetBreakOnLibraryErrors that mask the error and restore original flag state:
prevBOLE = SetBreakOnLibraryErrors (0);
MakeDir (...);
SetBreakOnLibraryErrors (prevBOLE);
09-19-2008 03:49 PM
You can just use GetFileAttrs from the Utility library (which returns 1 if the path is a directory, -1 if not found), or FileExists from the toolbox (which is actually just a thin wrapper for the GetFileSize Utility library function). The documentation doesn't mention that FileExists works for directories, but it does. Don't ask me what the value returned in the size parameter means though... 🙂
Mert A.
National Instruments
09-22-2008 04:37 AM
Thank you for all repplies!
I've tried the SetDir and MakeDir before, but I didn't know how to break on library errors.
It was always suspending my execution and I didn't know how to deal with it.
It works great, thanks a lot.
06-13-2013 06:18 PM
I have tried to use the GetFileAttrs(), but it didn't work, this function will popup LIB ERROR and break the project too.
06-14-2013 09:44 AM - edited 06-14-2013 09:44 AM
As Roberto posted earlier, before your call to GetFileAttrs, etc., just use SetBreakOnLibraryErrors(0) to disable breaking on library errors, then SetBreakOnLibraryErrors(1) to enable breaking after that.
Al S
06-03-2014 01:08 PM
hi guys,
i`m new at this so im gonne prob. ask a noob`s question...
i have the same issue as in the title.
but when i run :
int a,b,c,d,folderexist=-1;
switch (event)
{
case EVENT_COMMIT:
{
GetCtrlVal (panelHandle, PANEL_NAME, name);
folderexist = GetFileAttrs (name, &a, &b, &c, &d);
if (folderexist==-1)
{
MakeDir (name);
sprintf...........
}
else.......
if the folder do exists it works perfectly.
if it doesnt - it breaks the run and gives me the message :
NON-FATAL RUN-TIME ERROR: "NewScap.c", line 317, col 27, thread id 0x00001B98: Library function error (return value == -1 [0xffffffff]).
(and mark the getfileattrs line in blue)
and when i check the "folderexits" value it shows 2!? not 1 not 0 not even -1, but 2...
can somone please help ?
thanks
Adi.
06-03-2014 03:01 PM
Tnx Alot !
i`ve use ur solution.
it helped...
just have to ask...do i need to use it everytime ?
why does the function GetFileAttrs works without SetBreakOnLibraryErrors...?