WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Functions

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

FileDelete Returns a True, but File Still Shows up in Explorer

Keywords:     filedelete iniwritepvt

Question #1:

I'm using the FileDelete function on a file opened and closed with FileOpen/FileClose, and the filedelete is returning a 1, but the file is still there in Explorer. What's going on?

Answer:

On some systems, disk cacheing takes longer than should be expected. So if you're running into the above problem, try using the following script:
        file=FileOpen(...)
        FileClose(file)

        For i=1 to 5
           if FileExist(file)==1 then FileDelete(file)
        Next
Also note that as of Winbatch version 97A, FileDelete does not return a false if the file you are trying to delete does not exist. FileDelete will return a 1 if you try to delete a file that does not exist, therefore, be sure to test the existence of the file with FileExist before the FileDelete.

Question #2:

I am using the IniWritePvt and IniReadPvt functions to read and write values to an INI file. I am trying to delete a file, using the FileDelete function. I can see when I display the return value for FileDelete, that it returned a 1, meaning that it successfully deleted the file. However, when I go into Explorer to see if the file is deleted, the file miraculously reappears in 5-10 seconds. What's going on?

Answer:

When using File operations and INI functions, you can sometimes run into this problem. Windows likes to hold INI files in memory for 5-10 seconds, and if the information has changed, Windows will take a while before it writes it to the hard disk. Even though WinBatch has deleted the file from the harddrive, the file is still in memory, so Explorer will still find and display the INI file.

Do not mix file operations and INI operations. This is not a feature of WinBatch but of Windows. When you use iniWritePvt() to update an INI file, Windows broadcasts a message to everybody so that processes that have read the INI file know that the file needs to be re-read. Overwriting an INI file with File operations doesn't result in this broadcast. As a result, nobody, including WinBatch, will know that the file is changed, and everybody, including WinBatch, will use its buffered copy to continue processing.

If you use the IniWrite or IniWritePvt functions to update an INI file, Windows will take its own sweet time to update the copy of the file on disk. There is a trick to tell Windows to update the copy now.

The following is a workaround to force a disk update of an INI file:

     IniWritePvt("","","","INIFILE.INI")
     TimeDelay(1)
     FileDelete("INIFILE.INI")

Question #3:

I'm trying to delete a bunch of files in a directory, that I've itemized using the FileItemize function to go through each file before doing the delete. FileDelete returns a true, but the files aren't delete. What gives?

Here's my code:

fi=fileitemize("c:\Temp\*.bak")
count=Itemcount(fi,@TAB)

For x=1 to count
   file=Itemextract(x,fi,@Tab)
   test=Filedelete(file)
   
   If test==1
	Display(1,file,"Sucessfully deleted")	    
   Else
	Message("Problem","%file% not deleted")
   endif     
Next   
Message("Files deleted","Number of files = %Count%")


Answer:

Do a Dirchange just before your ItemExtract loop. FileItemize only returns a list of files, but not their paths.
Dirchange("C:\Temp")  ;IMPORTANT to make sure files are deleted from this dir

For x=1 to count
   file=Itemextract(x,fi,@Tab)
   ...

Article ID:   W13066
Filename:   FileDelete Returns True but File Shows up in Explorer.txt
File Created: 1999:04:15:16:51:32
Last Updated: 1999:04:15:16:51:32