LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how can I delete temp file in CVI?

I want to delete a temp file in labwindows/CVI using "DeleteFile ("C:/Windows/TEMP/temp1.tmp")",but it doesn't work.Who can tell me why?
0 Kudos
Message 1 of 6
(4,360 Views)
Hi Tim,

You shouldn't have a problem deleting a .tmp file using this function. Some things to check are if temp1.tmp is a file or a folder, if you have full permissions to access and modify that folder, and if the file still exists and is not in use. Another thing to check is the status returned from DeleteFile. This status code will give you more hints as to why it was unsuccessful.

if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
status = DeleteFile ("c:\\WINDOWS\\Temp\\temp1.tmp");

Jeremy L.
National Instruments
Jeremy L.
National Instruments
0 Kudos
Message 2 of 6
(4,360 Views)
Tim,

The DeleteFile function should allow you delete any file that you have permission to delete and that no other application is using.

I created a simple test code and I was able to delete the files in the temp folder. Make sure that you don�t keep a reference open for the file that you want to delete. Or that no other application is using the file. You can also set a breakpoint in the function and when you get there try to delete the file manually; most likely you'll get an error too.

I hope this helps, let us know if you have any further questions.

Regards,

Juan Carlos
N.I.
0 Kudos
Message 3 of 6
(4,360 Views)
I have done some test,but still can't delete any thing.The return code said -1,means what?Could you attach the test code?Thank you!
0 Kudos
Message 4 of 6
(4,360 Views)
According to the help for DeleteFile() a returned status of -1 means it couldn't find the file and/or the folder specified.

Check that the file actually exists by opening an explorer window on the directory you specified and verify that the 'TEMP1.TMP" file actually exists.

C:/Windows/TEMP/temp1.tmp

DeleteFile's Return Values are:
Code Description
0 Success.
-1 File not found or directory in path not found.
-3 General I/O error occurred.
-4 Insufficient memory to complete operation.
-5 Invalid path; for example, c:filename.
-6 Access denied.
-7 Specified path is a directory, not a file.
0 Kudos
Message 5 of 6
(4,360 Views)
Thank you !
0 Kudos
Message 6 of 6
(4,360 Views)