ahha Posted July 2, 2018 Share Posted July 2, 2018 (edited) This short script seems to show that FileDelete waits until the script exits before it actually deletes the files. I don't understand this. What am I missing? #AutoIt3Wrapper_run_debug_mode=Y ; use this to debug in console window <--- LOOK #include <File.au3> ;v1a - NOTE tried creating files in both %TEMP% and @WorkingDir and on my machine files there need admin to delete IF Autoit program has not exited. ;HMMM - FileDelete seems to work ONLY after Autoit program exits - not the behaviour I want. Tried in %TEMP% and @WorkingDir ;also tried creating files on USB drive so not subject to OS protections - same scenario - files don't delete till program exits. This is crazy - what the heck am I doing wrong? ;get unique filenames $sBatFile = _TempFile(@WorkingDir, "", ".bat") ;get bat file temp name $sOutputFile = _TempFile(@WorkingDir, "", ".res") ;get output file temp name MsgBox(0x40000,"STATUS", "$sBatFile = '" & $sBatFile & "'" & @CRLF & "$sOutputFile = '" & $sOutputFile & "'") ;create the unique files $hBatFile = FileOpen($sBatFile, $FO_OVERWRITE) $hOutputFile = FileOpen($sOutputFile, $FO_OVERWRITE) MsgBox(0x40000,"DEBUG", "Make sure these files exist." & @CRLF & "$sBatFile = '" & $sBatFile & "'" & @CRLF & "$sOutputFile = '" & $sOutputFile & "'") ;clean up $iDelete = FileDelete($sBatFile) If $iDelete = 0 Then MsgBox(0x40000,"DEBUG", "file: '" & $sBatFile & "' NOT deleted.") FileDelete($sOutputFile) If $iDelete = 0 Then MsgBox(0x40000,"DEBUG", "file: '" & $sOutputFile & "' NOT deleted.") MsgBox(0x40000,"DEBUG", "Make sure these files are DELETED" & @CRLF & "$sBatFile = '" & $sBatFile & "'" & @CRLF & "$sOutputFile = '" & $sOutputFile & "'") ;look in the directory BEFORE you hit OK in the above MsgBox and the files are NOT deleted and if you manually try you need admin permission Exit Edited July 2, 2018 by ahha Link to comment Share on other sites More sharing options...
ahha Posted July 2, 2018 Author Share Posted July 2, 2018 Please delete post. I just realized I forgot to Close the files before deleting. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now