LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Anyone done any neat routine for deleting all files and sub-directories?

Everyone,

I've tried to write a recursive routine using the GetFirstFile & GetNextFile routines etc. but to no-avail. I can't seem to get them to work properly. Anyone know how to do this in CVI? (I've seen the LabVIEW VI, but don't want to use that.)Any ideas would be appreciated!

Regards,
Brian
0 Kudos
Message 1 of 7
(5,217 Views)
Hello Brian,
I am not sure how it is not working properly, but the best way would be to set a break point and step inside the recursive routine and see which part of the code is causing the error.

Regards,
Mika Fukuchi
Applications Engineering
National Instruments
0 Kudos
Message 2 of 7
(5,217 Views)
I am using cvi 7.0 and can not delete full directories.  How can I simply delete full directories and directories containing sub folders?
0 Kudos
Message 3 of 7
(4,815 Views)
The function DeleteDir requires an empty directory and returns an error if the directory is not empty... So it appears that you will have first to delete all files and subfirectories. You can use the functions GetFirstFile and GetNextFile
0 Kudos
Message 4 of 7
(4,807 Views)

Here is another way to delete all files within a directory.

 

 LaunchExecutable ("cmd.exe /C rmdir C:\\junk2 /Q /S");    //deletes files from C:\junk2 folder and all dir and files within. 

 

 

 

Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 5 of 7
(4,800 Views)

Hi Brian,

 

I suggest you to use the SHFileOperation() Windows function (in shell32.dll).

If you have the Win32 API Interface (previous name - Windows SDK) it's easy to do that, and you can copy, move and delete a full directory tree.

 

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

-------------------------------------------
Using LV from 7
Using LW/CVI from 6.0
0 Kudos
Message 6 of 7
(4,754 Views)

Hello, if the folder where you saved the files you want to delete is for example c: \ test, then:

char fileName [MAX_PATHNAME_LEN];
GetFirstFile ("c: \ \ test", 1, 1, 0, 0, 0, 0, fileName);
DeleteFile ("*.*");

and then use the function "DeleteDir ()" to delete the folder

0 Kudos
Message 7 of 7
(4,157 Views)