LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to add folder in an existing project directory

Hi,
 
i was wondering if somebody can help with my problem. I am currently trying to add a folder in a current project directory.....Say for example..create a folder 1 in the current directory... so c:\UAP\Folder.........i tried using MakeDir("Folder").....so the first time it creates it....bt then the next tiem i open the program.....it goes to make it again but it already exists hence error....
 
Any suggestion to round this.
 
Thanks
 
k1_ke
0 Kudos
Message 1 of 6
(3,435 Views)

You want to turn off library errors:

int oldState;

int result;

oldState=SetBreakOnLibraryErrors(0);

result=MakeDir(filepath);

SetBreakOnLibraryErrors(oldState);

The value of result will be -9 if the directory previously existed.  If this is ok it can be treated as a successfull result.

If you know you will not be making a call to SetBreakOnLibraryErrors() before executing this routine you do not need to save the "old state" and can just bracket MakeDir() with SetBreakOnLibraryErrors(0) and SetBreakOnLibraryErrors(1) to disable error checking for this step.

 

 

0 Kudos
Message 2 of 6
(3,421 Views)

Hi.

 

You could use the FileExists() function from Programmer's Toolbox.

 

Try this:

#include <toolbox.h>

 

int exists, size, error;

 

exists = FileExists ("mydir\\.", &size);

if (!exists)

            error = MakeDir (“mydir”);

 

Using “mydir\\.” rather than “mydir” confirms that “mydir” is a folder, not just a regular file.

 

Regards,

Colin.

 

0 Kudos
Message 3 of 6
(3,412 Views)
Hi Colin,
 
Thank you very much for the reply. It worked out great for me.
 
Thanks
 
k1_ke
0 Kudos
Message 4 of 6
(3,389 Views)

Hi,

I was wondering how i can go about changing the project directory to the new path once i hv created a new folder....say i get the project directory....then i check if a folder exists, if not create it and then i want that to be the default project directory path. i tried calling get project dir but doesnt seem to change the path.

I would appreciate if you could guide me through.

Thanks

k1_ke

0 Kudos
Message 5 of 6
(3,362 Views)
SetDir command is what you need: it receives the pathname of the new directory as a parameter (no drive indication though: it works on the current drive. To se the current drive use SetDrive).


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 6 of 6
(3,357 Views)