borup Posted April 28, 2008 Posted April 28, 2008 Hello all. How do i compare to directories for file names? the same file name must not be in both folders. This is the code i got so far. $path1 = "C:\temp\" $path2 = "C:\temp1\" Code here ??? If $search = 0 then MsgBox(0, "OK", "No match where find!") Else MsgBox(0, "Error", "The file " & $search & " exist in both directories") End if
rasim Posted April 28, 2008 Posted April 28, 2008 Example: #include <File.au3> $path1 = "c:\Temp" $path2 = "c:\Temp1" $aFile = _FileListToArray($path1, "*.*", 1) Dim $Found For $i = 1 To $aFile[0] $search = FileFindFirstFile($path2 & "\" & $aFile[$i]) If $search = -1 Then ContinueLoop While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $Found &= $file & @LF WEnd Next FileClose($search) MsgBox(0, "Same files", $Found)
ppenchev Posted July 5, 2011 Posted July 5, 2011 Example: #include <File.au3> $path1 = "c:\Temp" $path2 = "c:\Temp1" $aFile = _FileListToArray($path1, "*.*", 1) Dim $Found For $i = 1 To $aFile[0] $search = FileFindFirstFile($path2 & "\" & $aFile[$i]) If $search = -1 Then ContinueLoop While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $Found &= $file & @LF WEnd Next FileClose($search) MsgBox(0, "Same files", $Found) Hi I just saw this code and find it very helpful and even used that script so i can check the directories for the files in them. But i found out that if there is one file missing in one of the directories no mistake is displayed. I wanted to ask if you can help me with that. How can we add a Error check. Like if there is File "Name1" in the first directory but this file is missing in the second Directory, a error message to be displayed. I know the question is stupid but i just started to learn autoit and I'm very new to this. Thanks in advance
brycetech Posted December 24, 2011 Posted December 24, 2011 #include <File.au3> comparedir() func comparedir() local $path1, $path2, $search, $aFile, $Found, $NotFound, $matchcount = 0, $notmatchcount = 0 $path1 = FileSelectFolder("Choose an initial folder.","",2,@ScriptDir) if $path1 <> "" then $path2 = FileSelectFolder("Choose a comparison folder.","",2,$path1) if $path2 <> "" then $aFile = _FileListToArray($path1, "*.*", 1) For $i = 1 To $aFile[0] $search = $path2 & "" & $aFile[$i] if FileExists($search) then $matchcount += 1 $Found &= $aFile[$i] & @LF Else $notmatchcount += 1 $notfound &= $aFile[$i] & @LF EndIf next Else msgbox(0,"Error","No Folder Selected") endif Else msgbox(0,"Error","No Folder Selected") endif consolewrite("Source Directory: " & $path1 & @crlf & "Compare Directory: " & $path2 & @crlf & @crlf) consolewrite("Same files: " & $matchcount & " matches found in " & $path2 & @crlf & @crlf & $Found & @crlf) consolewrite("Not Found files: " & $notmatchcount & " files missing in " & $path2 & @crlf & @crlf & $NotFound & @crlf) endfunc
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