Error 1016: FileDelete File Not Found
Keywords: 1016 filedelete
Question:
Exactly what conditions cause the error 1016: FileDelete File not found?I have the following code in a winbatch script:
If FileExist("spslocks.dat") == @FALSE Then goto upload FileDelete("spslocks.dat") FileWrite(logHandle, strCat(TimeDate(), " spslocks.dat deleted.")) :upload Run("wupload.exe", "immediate USERLIST(UPLIST.DAT) OLDDBD")Usually the code works, but sometimes I get 1016: FileDelete file not found FileDelete["spslocks.dat"].The file exists, but it might have been in use when the FileDelete that failed was issued. Is it possible that file in use or some permission failure is causing the file not found error?
Answer:
Well, not sure what the problem is.FileExist will search the path for the file. FileDelete will not. Is the file marked read-only, or does it belong to a running EXE file, or is it open by a running application? Will DOS DelTree delete this file?
Can you write a one line script to delete the file that it fails on?
If FileExist returns a 2, meaning that it is opened in read deny mode by another application, it is unlikely a delete operation would be successful.
There seem to be at least two possibilities in your situation:
Try this version of the code....
- FileExist *might* be finding the file someplace else. If FileExist is not given a full path, it will root through the PATH looking for the file.
- The file name ... spslocks ... leads me to believe you are tring to create a resource lock. If you search the database for "resource lock" you'll find an example script of how to make a resource lock.
curdir=DirGet() If FileExist("%curdir%spslocks.dat") == @FALSE Then goto upload If FileExist("%curdir%spslocks.dat") == 1 FileDelete("spslocks.dat") FileWrite(logHandle, strCat(TimeDate(), " spslocks.dat deleted.")) else FileWrite(logHandle, strCat(TimeDate(), " spslocks.dat file in use !!!!.")) endif :upload Run("wupload.exe", "immediate USERLIST(UPLIST.DAT) OLDDBD")More FileDelete Questions:
The following code produces the "Error 1016: FileDelete: File not Found" error message:If FileExist("c:\ifprot.exe") FileDelete("c:\ifprot.exe") EndIfDebug shows:If FileExist("c:\ifprot.exe") IF DO ==> TRUEThe FileDelete statement is the very last command in the program IFPROT.EXE, which is the file I'm trying to delete. I'm trying to clean up by deleting the program after it ends. Maybe this is the problem. If so, how would you remove a program from the hard drive after it completes execution?What I want is to have the program delete itself from the hard drive after execution is complete.
Answer:
Maybe....
- You cannot delete a running EXE.
- If you did want to clean it up, there may be more files involved (DLL's etc).
- One solution is to put it in the user TEMP directory and they'll delete it eventually.
fn="c:\xxx.exe" if WinMetrics(-4)==4 ;NT IntControl(30,fn,"",0,0) endif if WinMetrics(-2)==5 ;95 wininitfile=strcat(DirWindows(0),"wininit.ini") if FileExist(wininitfile) ff=FileOpen(wininitfile,"APPEND") FileWrite(ff,strcat("NUL=",fn)) FileClose else ff=FileOpen(wininitfile,"WRITE") FileWrite(ff,"[rename]") FileWrite(ff,strcat("NUL=",fn)) FileClose endif endifFor 32 bit system this will delete the fn file at next reboot.You *might* try ShellExecute-ing something else, (eg COMMAND.COM /c), to delete the EXE. Not sure whether or not this will work.
Even More FileDelete Questions:
I am attempting to delete a shortcut on the desktop. I am getting the 1016 file not found. However FileExist is returning 1(meaning the file does exist) and the if condition is executed, but I am still getting the error 1016 "FILE NOT FOUND"! Why would that be????
fx= FileExist("c:\windows\profiles\desktop\allusers\desktop\update.lnk") If fx==1 FileDelete("c:\windows\profiles\desktop\allusers\desktop\update.lnk") EndIfANSWER:
Most likely the file you are attempting to delete has the read-only file attribute set. The FileDelete function will not delete files that have the read-only attribute set. You can get the attributes using a function in Winbatch called FileAttrGet, and you can set the attributes using the function FileAttrSet. Try the following:FileAttrSet ("c:\windows\profiles\desktop\allusers\desktop\update.lnk", "r");turns read-only off fx= FileExist("c:\windows\profiles\desktop\allusers\desktop\update.lnk") If fx==1 FileDelete("c:\windows\profiles\desktop\allusers\desktop\update.lnk") EndIf
Article ID: W12934Filename: 1016 FileDelete File Not Found.txt