WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

File Operations

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Comparing Two Directories

Keywords: 	 compare directories

TestFirstDir="C:\temp\"
TestSecondDir="C:\incoming\"

DirChange(TestFirstDir)  
ListDir1=StrLower(FileItemize("*.*"))
ListDir1=ItemSort(ListDir1,@tab)
CountDir1=StrLower(ItemCount(listDir1,@tab))
DirChange(TestSecondDir)  
ListDir2=FileItemize("*.*")
ListDir2=ItemSourt(ListDir2,@tab)
CountDir2=ItemCount(listDir2,@tab)
;;;;;;
FilesInFirstNotInSecond=ListDir1
for xx=1 to CountDir2
    testfile=ItemExtract(xx,ListDir2,@tab)
    test=ItemLocate(testfile,FilesInFirstNotInSecond,@tab)
    if test != 0
       FilesInFirstNotInSecond=ItemRemove(test,FilesInFirstNotInSecond,@tab)
    endif
next
;;;;;;
FilesInSecondNotInFirst=ListDir2
for xx=1 to CountDir1
    testfile=ItemExtract(xx,ListDir1,@tab)
    test=ItemLocate(testfile,FilesInSecondNotInFirst,@tab)
    if test != 0
       FilesInSecondNotInFirst=ItemRemove(test,FilesInSecondNotInFirst,@tab)
    endif
next
;;;;;;
FilesInBoth=""
FilesInBothAndDifferent=""
For xx=1 to CountDir1
    testfile=ItemExtract(xx,ListDir1,@tab)
    test=ItemLocate(testfile,Listdir2,@tab)
    if test!=0
       if FileInBoth=="" then FileInBoth=testfile
       else FilesInBoth=Strcat(FilesInBoth,@tab,testfile)

       testfile1=Strcat(TestFirstDir,testfile)
       testfile2=Strcat(TestSecondDir,testfile)
       comptest=FileCompare(testfile1,testfile2)

       if comptest!=0
          if FilesInBothAndDifferent=="" then FilesInBothAndDifferent=testfile
          else FilesInBothAndDifferent=Strcat(FilesInBothAndDifferent,@tab,testfile)
       endif
    endif
next

;;;;;

AskItemList("Only in %TestFirstDir%",FilesInFirstNotInSecond,@tab,@unsorted,@single)
AskItemList("Only in %TestSecondDir%",FilesInSecondNotInFirst,@tab,@unsorted,@single)
AskItemList("Files in both",FilesInBoth,@tab,@unsorted,@single)
AskItemList("Files ib both but different",FilesInBothAndDifferent,@tab,@unsorted,@single)








       

Article ID:   W14589
Filename:   Compare Directories.txt
File Created: 2000:09:21:14:55:08
Last Updated: 2000:09:21:14:55:08