AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

A folder comparison script

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
bradglaser



Joined: 14 Jan 2006
Posts: 3
Location: Tooele, UT

PostPosted: Sun Mar 18, 2007 4:44 pm    Post subject: A folder comparison script Reply with quote

Hey I'm kind of a newish coder and I was wondering if there was anyone out there that could write a script that would compare the content of two folders and say which files weren't in one or the other.

Thank you in advance.

Forever
Φφ Phi-Rho Φφ
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
PhiLho



Joined: 27 Dec 2005
Posts: 6836
Location: France (near Paris)

PostPosted: Sun Mar 18, 2007 10:00 pm    Post subject: Reply with quote

I am working on such script, for my own needs (management of translations for a PHP application). It isn't very hard to do, but I have little time. Will update here later.
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
engunneer



Joined: 30 Aug 2005
Posts: 8255
Location: Maywood, IL

PostPosted: Tue Mar 20, 2007 3:46 am    Post subject: Reply with quote

a very good free program that will tell you this is winmerge (winmerge.sf.net)
_________________

(Common Answers)
Back to top
View user's profile Send private message Visit poster's website
Dippy46



Joined: 06 Jul 2004
Posts: 171
Location: Manchester, England.

PostPosted: Tue Mar 20, 2007 8:25 am    Post subject: Reply with quote

@bradglaser,

Quick + dirty solution, but fast

Code:


;; check for files that ARE on h:\ that are NOT on g:\
;; does NOT perform a copy ! only informs what WOULD be copied :)

RunWait , %comspec% /c xcopy h:\*.* g:\*.* /s /y /d /l >> difference.txt , , hide

msgbox Done



_________________
Simple ideas lie within reach, only of complex minds
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6836
Location: France (near Paris)

PostPosted: Tue Mar 20, 2007 10:21 am    Post subject: Here it is Reply with quote

Neither very much tested (but seems to behave reasonably well) nor optimized!
Code:
;~ dir1 = D:\www\ZC-1.3.7\includes\languages\english
;~ dir2 = D:\www\ZC-1.3.7\includes\languages\french
dir1 = E:\javalib1
dir2 = E:\javalib2
;~ fileMask = *.php
fileMask = *.jar

Loop %dir1%\%fileMask%
{
   fileList1 .= A_LoopFileName . "`n"
   fnb1 := A_Index
}
StringTrimRight fileList1, fileList1, 1

Loop %dir2%\%fileMask%
{
   fileList2 .= A_LoopFileName . "`n"
   fnb2 := A_Index
}
StringTrimRight fileList2, fileList2, 1

Sort fileList1
Sort fileList2
StringSplit files_1_, fileList1, `n
StringSplit files_2_, fileList2, `n
idxF1 := idxF2 := 1

Loop
{
   If (files_1_%idxF1% = files_2_%idxF2%)
   {
      ; We are in synch
      list1 .= files_1_%idxF1% . "|"
      idxF1++
      list2 .= files_2_%idxF2% . "|"
      idxF2++
   }
   Else
   {
      ; Either file at idxF1 or at idxF3 is missing, we must find which one
      If (files_1_%idxF1% > files_2_%idxF2%)
      {
         ; Missing in first list
         list1 .= " |"   ; Empty
         list2 .= files_2_%idxF2% . "|"
         idxF2++
      }
      Else
      {
         ; Missing in second list
         list1 .= files_1_%idxF1% . "|"
         idxF1++
         list2 .= " |"   ; Empty
      }
   }
   If (idxF1 > fnb1)
   {
      Loop % fnb2 - idxF2 + 1
      {
         list1 .= " |"   ; Empty
         list2 .= files_2_%idxF2% . "|"
         idxF2++
      }
      Break
   }
   If (idxF2 > fnb2)
   {
      Loop % fnb1 - idxF1 + 1
      {
         list1 .= files_1_%idxF1% . "|"
         idxF1++
         list2 .= " |"   ; Empty
      }
      Break
   }
}

StringTrimRight list1, list1, 1
Gui Add, ListBox, w200 r20 vfiles1, %list1%
StringTrimRight list2, list2, 1
Gui Add, ListBox, x+20 w200 r20 vfiles2, %list2%

Gui Add, Button, w50 gGuiOK default, OK
Gui Add, Button, x+50 w50 gGuiClose, Cancel
Gui Show, w500
Return

GuiOK:
GuiClose:
GuiEscape:
ExitApp

I must find a way to synchronize the scrolling of the list boxes...
At worse, by providing Up and Down buttons between the lists.

Of course, this can be adapted to compare file content and such.
It won't make a good diff utility, as I must sort the data: file content comparison is much harder, I studied the topic a bit, it can lead to very CPU intensive algorithms, unless some tricks are used.
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group