Hi there!
I'm trying to delete old folders that are not in use anymore - the names of those folders are in a text file.
So what I want to do is have the script read the text file and compare the names in it to the actual folder names inside, and if the folder name from the list is found on the computer - delete it.
I am using filereadline to read from the text file, and _FileListToArrayRec to compare with the actual folders on the computer, but I need some help with the basic code. would appreciate the help..
AutoIt
#include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <file.au3> #Include <Date.au3> #include <Array.au3> ; ***** Create local logs DirCreate (@scriptdir & "test") $dir = (@scriptdir & "test"") $log = FileOpen (@scriptdir & "test"\test.log",2) ; Function for reading - text file Eof() Func Eof() ; Create a constant variable in Local scope of the filepath that will be read/written to. Global Const $sFilePath = @scriptdir & "\systems.txt" ; Open the file for reading and store the handle to a variable. Global $hFileOpen = FileOpen($sFilePath, $FO_READ) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.") Return False EndIf ; Read the contents of the file using the handle returned by FileOpen. Global $sFileRead = FileReadLine($hFileOpen, 1) ; Close the handle returned by FileOpen. ;FileClose($hFileOpen) ; Display the contents of the file. MsgBox($MB_SYSTEMMODAL, "", "Contents of the file:" & @CRLF & $sFileRead) EndFunc ; put the root in a variable $sRoot = (@ScriptDir) ; Retrieve a list of all the folders in $sRoot, and store them as an array in $aList Global $aList = _FileListToArrayRec ($sRoot, "*", 2, -2, 2) ; _FileListToArray("path" [, "Filter" [, Flag]]) ; Look at what _FileListToArray() puts into $aList _ArrayDisplay($aList) ; This is a loop that runs from 1 to the number of items listed in the first element of the returned array For $i = 1 To $aList[0] If $sFileRead = $sRoot & "\" & $aList[$i] Then _filewritelog ($log, "Deleting, " & $sFileRead) EndIf Next FileClose($hFileOpen)