Compare folders

Need new test, action, option? Post request here.
Post Reply
ssochs
Posts: 4
Joined: Fri Jan 21, 2005 2:55 am

Compare folders

Post by ssochs »

Hello,

i need a function to compare two folders for existence of files. Both folders must have the same number of files. The date/time are not interessting.

Thanks
dirk
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

I think you may create Java or VB script and start that script using Active Script or Shell Script test methods.
http://www.ks-soft.net/hostmon.eng/mfra ... htm#script
http://www.ks-soft.net/hostmon.eng/mfra ... m#chkShell

"FileSystemObject" provides access to file system. Use "GetFolder" method and "Files" property of "Folder" object
http://msdn.microsoft.com/library/defau ... erence.asp

Something like

Code: Select all

const statusAlive       = "Host is alive:"
const statusDead        = "No answer:"
const statusUnknown     = "Unknown:"
const statusNotResolved = "Unknown host:"
const statusOk          = "Ok:"
const statusBad         = "Bad:"
const statusBadContents = "Bad contents:"

Function CountFiles(foldername) 
   Dim fso, f1, fc, cnt 
   Set fso = CreateObject("Scripting.FileSystemObject") 
   Set fc = fso.GetFolder(foldername).Files
   cnt = 0 
   For Each f1 in fc 
      'here you may check for some specifiec name of the file... 
      cnt = cnt + 1 
   Next 
   CountFiles=cnt 
End Function 

FUNCTION PerformTest() 
  IF CountFiles("c:\folder1\")<>CountFiles("c:\folder2\") THEN 
     PerformTest = statusBad 
  ELSE 
     PerformTest = statusOk
  END IF 
END FUNCTION 
Regards
Alex
Post Reply