Jump to content

FileDelete problems


Recommended Posts

I made an AutoIt script to delete segmented AVI TV capture files. These files are in the format of "capture_x.yy.avi" where x = some one or two digit number and yy = some two digit number between 00 and 19. The script first asks for the x value (or uses the value defined by the command line). Then it searches for files with the x value and yy values between 00 and 19 on drives I:\ and E:\ and writes them to the $DeleteList variable separated by @CRLF if found. The next part of the script displays the list and asks if the user wants the files to be deleted, then deletes them if he does.

It works fine except that it somehow ALWAYS deletes files even if they are in use. What I mean is that if I'm encoding a group of files (so all of the files that share an x value are in use), it operates normally and just waits until those files are no longer being used and deletes them. I don't have a clue how; the script has closed by that point. I want it to pop up a box saying that it couldn't delete the files and not delete them, if ANY of the files in $DeleteList are in use.

Here's the script that works but always deletes the files:

If $CmdLineRaw <> "" Then
   $Name = $CmdLineRaw
Else
   $Name = InputBox ("Capture Cleanup", "Number of the captured video to delete", "1", "", -1, 100)
   If @error = 1 Then
      Exit
   EndIf
EndIf

$cNUM = "00"
$DeleteList = ""
$inc = 1

While $cNUM < 19
   If FileExists ("I:\capture_" & $Name & "." & $cNUM & ".avi") Then
      $DeleteList = $DeleteList & "I:\capture_" & $Name & "." & $cNUM & ".avi" & @CRLF
   ElseIf FileExists ("E:\capture_" & $Name & "." & $cNUM & ".avi") Then
      $DeleteList = $DeleteList & "E:\capture_" & $Name & "." & $cNUM & ".avi" & @CRLF
   EndIf
   If $cNUM < 9 Then
      $cNUM = "0" & ($cNUM + 1)
   Else
      $cNUM = $cNUM + 1
   EndIf
WEnd

If $DeleteList = "" Then
   MsgBox (0, "Capture Cleanup", "No files to delete")
Else
   $Delete = MsgBox (4, "Capture Cleanup", "Delete files?" & @CRLF & $DeleteList)
   If $Delete = 6 Then
      $Files = StringSplit ($DeleteList, @CRLF)
      While $inc <= $Files[0]
         FileDelete ($Files[$inc])
         $inc = $inc + 1
      WEnd
      MsgBox (0, "Capture Cleanup", "Deleted files")
   ElseIf $Delete = 7 Then
      Exit
   EndIf
EndIf

I modified part of it to be:

While $inc <= $Files[0]
   If FileDelete ($Files[$inc]) = 0 Then
      MsgBox (0, "Capture Cleanup", "Could not delete files")
      Exit
   EndIf
   $inc = $inc + 1
WEnd

This caused the script to just delete the first file in the $DeleteList, pop up the "Could not delete files" box, and close (and if the first file was in use, still pop up the box and close but still delete the file as soon as the file wasn't being used anymore).

Any ideas? Is there some function to check if a file is in use?

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...