header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Find equal files
Last Post 07 Jun 2008 03:21 AM by bruceatk. 3 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Iceman75User is Offline
New Member
New Member
Posts:22
Avatar

--
04 Jun 2008 08:11 AM  

Hi, I am working on a script to find equal files.

A user has two directories (with subdirectories in each one). If there there are equal files in both directories the script should output that, with showing the Path. Any suggestions how I can accomplish that??

Greetz

Ice

bsonposhUser is Offline
Basic Member
Basic Member
Posts:393
Avatar

--
04 Jun 2008 01:08 PM  
Define equal.

Same Name?
Same Size?
Same MD5 Hash?
Brandon Shell
----------------
Microsoft Powershell MVP
https://mvp.support.microsoft.com/profile/Brandon
Blog: http://www.bsonposh.com
Iceman75User is Offline
New Member
New Member
Posts:22
Avatar

--
05 Jun 2008 10:19 AM  

IF they have the same name and content then I want to out-file it.

If they have the same name but different content ( see it by size) then I want to have an extra out-file

 

Greetz

This is what I Hav so far

 


[string]$folder01 = "C:\OLDDATA"
[string]$folder02 = "C:\Ebeling"

$child_folder02 = $(get-childitem $folder02 -Recurse)

Write-Host "SideIndicator   FileName                   Path"
Write-Host "-------------   ------------------------   ------------------"
Compare-object -ReferenceObject $(get-childitem $folder01 -Recurse) -DifferenceObject $(get-childitem $folder02 -Recurse) -includeequal -PassThru -Property Name | Sort-Object -Property Name | foreach {
 # Process only files
 if ($_.mode -notmatch "d") {
  Write-Host $_.SideIndicator.toString().padright(15)$_.Name.tostring().padright(26)$_.FullName.tostring().padright(50)
  if ($_.SideIndicator -match "==") {
   $double_filename = $_.Name
   $child_folder02 | foreach {
    if ($double_filename -eq $_.Name) {
     Write-Host "                                          "$_.FullName
    }
   }
  }
 }
}

bruceatkUser is Offline
New Member
New Member
Posts:12
Avatar

--
07 Jun 2008 03:21 AM  
I just recommended Robocopy in a different post. The same here. Robocopy let's you do a directory comparison, sort of a practice copy. Using the /L parm causes it to compare two folders and log the results. That output can be captured in PowerShell.

$FileCompare = robocopy Dir1 Dir2 /E /L /IS /FP

This will cause robocopy to compare the folders and /IS tells robocopy to include files that are the same in the output. /FP option will output full pathname for each file. If you want to remove all the other files from the output you can use these additional parms.

/XC - eXclude Changed files.
/XN - eXclude Newer files.
/XO - eXclude Older files.
/XX - eXclude eXtra files and directories.
/XL - eXclude Lonely files and directories.

I have done several comparisons of these types and it has always been faster for me to use the combination then to try to do everything in Powershell. The memory requirements for loading up two giant directory structures can get out of hand pretty quick.

Bruce
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer