Sign in to follow this  
Followers 0
jfitty

Compare files in directories and subdirectories

17 posts in this topic

Hey guys,

I' wondering if someone would be able to help me. I'm looking for a script that can compare files in directories and subdirectories. I've done a few searches of the forum, but cant seem to find what I'm looking for. I want it to be able to compare the two directories, and then output a list of files that don't exist in one directory but do in the other.

For example:

filecompare dir1 dir2

After the script has run, it outputs a .txt file or an array that lists files that are in dir1 but not in dir2

Thanks in advance

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hey guys,

I' wondering if someone would be able to help me. I'm looking for a script that can compare files in directories and subdirectories. I've done a few searches of the forum, but cant seem to find what I'm looking for. I want it to be able to compare the two directories, and then output a list of files that don't exist in one directory but do in the other.

For example:

filecompare dir1 dir2

After the script has run, it outputs a .txt file or an array that lists files that are in dir1 but not in dir2

Thanks in advance

Submit a request at http://www.c4free.info if you like.

Edited by P5ych0Gigabyte

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

SMF can do... search for duplicates and filter for none duplicates in final report, right click export to txt...

its not a autoit program its a unix program but it can run on windows its called rsync

rsync can sync folder on local computer but it can olso connect to a rsync server and sync over network whatever u like here are some links to tutorials

http://www.novell.com/coolsolutions/trench/8921.html

http://stam.blogs.com/8bits/2007/12/rsync-voor-wind.html

my opinion this was the best

http://www.ratsauce.co.uk/notablog/UsingRsync.asp

Share this post


Link to post
Share on other sites

Thanks for the replies fellas. I've had a look at rsync, and it was very hard to work out. I did manage to get it working, but for some reason it took ages just to copy an empty text file I used as a test

Share this post


Link to post
Share on other sites

If you were really bent on doing something like this in AutoIt, you might want to look at the command line program 'fc' to do file comparisons, and use that in conjunction with a 'FindFileFirstFile' handle or something.

Just a thought, though the other answers suggested are probably easier.

Share this post


Link to post
Share on other sites

I think rsync would do the job. I just need some examples of how to use it locally

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I think rsync would do the job. I just need some examples of how to use it locally

just search on google on "how to use rsync" or "rsync local" something like that i only use rsync for backup's over internet

u can set rsync in windows scheduler so planned backups works fine i cannot say how to use it local but its very easy that what i know for sure.

**UPDATE**

look here

http://forums.macnn.com/90/mac-os-x/382306/rsync-command-to-sync-two-folders/

now u are wondering where or how u can get rsync:

read here how to get rsyc:http://www.ratsauce.co.uk/notablog/UsingRsync.asp

Edited by yucatan

Share this post


Link to post
Share on other sites

To compare files and directories I use WinMerge. It does what you want and a lot more. IT#s open source.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

If you are looking to compare the existance of files only then just use

#include<File.au3>
$sDir_1 = "C:\Somefolder\"
$sDir_2 = "C:\another folder\"
$aFiles = _FileListToArray("dir1", *, 1)

For $i = 1 To Ubound($aFiles)-1
    If FileExists($sDir_2 & $aFiles[$i]) Then ContinueLoop
    FileCopy($sDir_1 & $aFiles[$i], $sDir_2 & $aFiles[$i])
Next

Edit: Forgot the code tags

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Here is an example script. The function compare returns the files that are in folder one but not folder 2 in an array. You can pull out the function and use it in your own script. It requires the second function below it to function.

#Include<Array.au3>

$Array=Compare(@ScriptDir&"\1",@ScriptDir&"\2")

_ArrayDisplay($Array)
Func Compare($sDir1,$sDir2)
    $as1=Dir_BS($sDir1)
    $as2=Dir_BS($sDir2)
    If Not (IsArray($as1) and IsArray($as2)) then Return -1
    $iLen=StringLen($sDir1)+1
    For $iN=1 to $as1[0]
        $as1[$iN]=StringTrimLeft($as1[$iN],$iLen)
    Next

    $iLen=StringLen($sDir2)+1
    For $iN=1 to $as2[0]
        $as2[$iN]=StringTrimLeft($as2[$iN],$iLen)
    Next
    $sMissing=""
    For $iN=1 to $as1[0]
        If _ArraySearch($as2,$as1[$iN])=-1 Then $sMissing&=$as1[$iN] &@CRLF
    Next
    Return StringSplit(StringTrimRight($sMissing,2),@CRLF,1)
EndFunc


Func DIR_BS($sDir)
    $hPID=Run(@ComSpec & ' /c dir /b /s "'&$sDir&'"',@ScriptDir,@SW_HIDE,0x2)
    ProcessWaitClose($hPID)
    $asSplit=StringSplit(STDOUTREAD($hPID),@CRLF,1)
    Return $asSplit
EndFunc

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

Thanks for the posts guys! Does it search the folders recursively though?

Share this post


Link to post
Share on other sites

Thanks for the posts guys! Does it search the folders recursively though?

Are you asking about the script I provided? Yes it does. =)


HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

nice!! ill try it out and see how it goes

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

You could even employ some other useful functions to compare the files.

FileGetSize
FileGetTime
FileGetVersion
FileGetAttrib

or dare I even suggest (intermediate+ AutoIt scripting)

FileRead
Edited by spudw2k

Share this post


Link to post
Share on other sites

Thanks for the posts guys! Does it search the folders recursively though?

You didn't mention recursion so I didn't worry about it.

I have a nice _Folder_ListToArray() but I haven't gotten to the point of doing the same for files yet.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Here is an example script. The function compare returns the files that are in folder one but not folder 2 in an array. You can pull out the function and use it in your own script. It requires the second function below it to function.

#Include<Array.au3>

$Array=Compare(@ScriptDir&"\1",@ScriptDir&"\2")

_ArrayDisplay($Array)
Func Compare($sDir1,$sDir2)
    $as1=Dir_BS($sDir1)
    $as2=Dir_BS($sDir2)
    If Not (IsArray($as1) and IsArray($as2)) then Return -1
    $iLen=StringLen($sDir1)+1
    For $iN=1 to $as1[0]
        $as1[$iN]=StringTrimLeft($as1[$iN],$iLen)
    Next

    $iLen=StringLen($sDir2)+1
    For $iN=1 to $as2[0]
        $as2[$iN]=StringTrimLeft($as2[$iN],$iLen)
    Next
    $sMissing=""
    For $iN=1 to $as1[0]
        If _ArraySearch($as2,$as1[$iN])=-1 Then $sMissing&=$as1[$iN] &@CRLF
    Next
    Return StringSplit(StringTrimRight($sMissing,2),@CRLF,1)
EndFunc


Func DIR_BS($sDir)
    $hPID=Run(@ComSpec & ' /c dir /b /s "'&$sDir&'"',@ScriptDir,@SW_HIDE,0x2)
    ProcessWaitClose($hPID)
    $asSplit=StringSplit(STDOUTREAD($hPID),@CRLF,1)
    Return $asSplit
EndFunc

This works really well! The only thing is it takes a while with large directories. Would there be any way to make it faster?

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0