kjcdude Posted January 15, 2008 Posted January 15, 2008 (edited) I need to be able to compare two directories, or compare one directory to a static ini file, then delete all the files that shouldn't exist compared to the master directory. Below is what i have now, it's not working as it should. I'm very new to arrays which is what i believe is messing me up. FileChangeDir("C:\Program Files\system\core\") $search = FileFindFirstFile("*.ext") $dtmodified = @mon & "/" & @mday & "/" & @YEAR & " - " & @hour & ":" & @min & ":" & @sec $compnum = StringRight(@ComputerName, 3) $logini = "\\nas01\Volume_1\Update System\Log\11-24-07 - " & $compnum & ".ini" $appslist = "\\nas01\Volume_1\Update System\Updates\apps-ext.ini" $appsini = IniReadSection($steamappslist, "EXT_EXISTS") IniWrite($logini, "Modified", "When", $dtmodified) while 1 $searchfake = FileFindFirstFile("*.ext") For $i = 1 To $appsini[0][0] $finder = FileFindNextFile($search) If @error Then ExitLoop if $finder = $appsini[$i][1] Then Else IniWrite($logini, "EXT_DEL", $searchfake, $finder) EndIf Next WEnd $del = IniReadSection($logini, "EXT_DEL") For $i = 1 To $del[0][0] FileDelete("C:\Program Files\system\core\" & $del[$i][1]) Next Edited January 15, 2008 by kjcdude
smashly Posted January 15, 2008 Posted January 15, 2008 Hi, seems easy enough, here's an example reading an ini with file names to keep and looking in a directory to compare against the ini, if the directory has files that aren't in the ini then they are deleted.#include <File.au3> DelViaIni(@ScriptDir & "\Compare.ini", "Compare", "C:\Test") ; Parameters for DelViaIni() function; ; $IniPath = Path to ini that contains the file names to keep ; $sName = Section name in the ini to read ; $cPath = The Directory to compare and delete files from. Func DelViaIni($IniPath, $sName, $cPath) Local $IRS, $FL2A $IRS = IniReadSection($IniPath, $sName) If @error <> 1 Then $FL2A = _FileListToArray($cPath, "*", 1) If @error = 0 Then For $i = 1 To $FL2A[0] If $FL2A[$i] <> Check($FL2A[$i], $IRS) Then FileDelete($cPath & "\" & $FL2A[$i]) Next EndIf EndIf EndFunc ;Helper function Func Check($iFile, $aIRS) For $j = 1 To $aIRS[0][0] If $ifile = $aIRS[$j][1] Then Return $ifile Next Return "" EndFunc Here's what I used for an ini[Compare] File1=New AutoIt v3 Script.au3 File2=New AviSynth Script.avs File3=New Text document.txt As you can see I created a directory C:\Test , I then added some dummy files into the directory, I ran the script with the ini in another directory... I think it would be fairly easy to do the same thing via a main directory and another directory compare/delete without using an ini. Cheers
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