Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Delete specific folder found in a text file

$
0
0

Hello,

 

I am trying to build a script that reads a text file with multiple lines (every line has a folder name that needs to be deleted).

Then I want to look for the folder name in the folder list (using _FileListToArrayRec) and if the folder name is found - delete it.

 

This is the code I have so far, but it fails on line 43 - "Array variable has incorrect number of subscripts or subscript dimension range exceeded"
would appreciate some help.

AutoIt         
  1. #include <FileConstants.au3>
  2. #include <MsgBoxConstants.au3>
  3. #include <file.au3>
  4. #Include <Date.au3>
  5. #include <Array.au3>
  6.  
  7. ; ***** Create local logs
  8. $dir = (@WindowsDir & "\Log\")
  9. $log = FileOpen (@WindowsDir & "\Log\log.log",2+256)
  10.  
  11. Eof()
  12.  
  13. Func Eof()
  14.     ; Create a constant variable in Local scope of the filepath that will be read/written to.
  15.     Global Const $sFilePath = @scriptdir & "\folders.txt"
  16.  
  17.     ; Open the file for reading and store the handle to a variable.
  18.     Global $hFileOpen = FileOpen($sFilePath, $FO_READ)
  19.     If $hFileOpen = -1 Then
  20.         MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")
  21.         Return False
  22.     EndIf
  23.  
  24.     ; Read the contents of the file using the handle returned by FileOpen.
  25.  
  26.      Global $aArray = FileReadToArray ($hFileOpen)
  27.       For $i = 0 To UBound($aArray) - 1 ; Loop through the array.
  28.             MsgBox($MB_SYSTEMMODAL, "", $aArray[$i])
  29.  
  30. $sRoot = (@ScriptDir)
  31.  
  32. ; Retrieve a list of all the folders in $sRoot, and store them as an array in $aList
  33. Global $aList = _FileListToArrayRec ($sRoot, "*", 2, -2) ; _FileListToArray("path" [, "Filter" [, Flag]])
  34. ; Look at what _FileListToArray() puts into $aList
  35. For $i = 1 To $aList[0]
  36.  
  37.  
  38. If FileExists($sRoot & "\" & $aList[$i] & "\" & $aArray[$i])  Then _filewritelog ($log, "Deleting, " & $aArray[$i])
  39. FileClose($hFileOpen)

Viewing all articles
Browse latest Browse all 12506

Trending Articles