Tsiyoshi Posted March 11, 2015 Share Posted March 11, 2015 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.. expandcollapse popup#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) Link to comment Share on other sites More sharing options...
orbs Posted March 11, 2015 Share Posted March 11, 2015 if your text file stores full path of folders (which is absolutely insane if it doesn't), then there is no need for _FileListToArrayRec(). instead, use FileExists() on every line read from the text file. other than that, what is the difficulty you are experiencing? Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
Tsiyoshi Posted March 11, 2015 Author Share Posted March 11, 2015 Thanks you. I can use FileExists() but to the best of my knowlege, I can run the search from the text file on a root folder directory, for example: If FileExists(@ScriptDir & "\" & $sFileRead) But I need the search to run on numerous subfolders (which is why I thought about using _FileListToArrayRec. 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