Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1501
  • Last Modified:

Compare two folders (Total size, Total number of files, Total number of Folders)

We are moving user's folder from one location to another....Once we finsih we need to verify the source and target location to confirm the Total size, Total number of files, Total number of Folders are same at both locations....

Fine with VB or Powershell
0
principiamanagement
Asked:
principiamanagement
2 Solutions
 
AnuroopsunddCommented:
$fso = Get-ChildItem -Recurse -path C:\fso

$fsoBU = Get-ChildItem -Recurse -path C:\fso_BackUp

Compare-Object -ReferenceObject $fso -DifferenceObject $fsoBU

 The output tells me that inputobject (this is the difference object parameter) is missing three files: a.txt, b.txt, and c.txt. I need to copy these three files to the c:\fso_backup folder

http://blogs.technet.com/b/heyscriptingguy/archive/2011/10/08/easily-compare-two-folders-by-using-powershell.aspx
0
 
suresh_bogaCommented:
Dont move - first take backup then copy and then compare so that you will not  loose data
For  copying files from one location to another. Use Robocopy - and enable logging option. IF there are any difference then LOg file give you complete information.
0
 
principiamanagementAuthor Commented:
Hi Suresh,

Well we are not moving...We are only copying from one location to other..We use more advance tool than robocopy called EMCcopy ...

Anuroop, I am comparing the folders using below code...

Dim objShell 
Dim objExecObject 
Dim strText  
Dim command  
Dim Directory

Directory = Wscript.Arguments(0)

command = "cmd /c dir " & Directory & " /s"

Set objShell = CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec(command)
 

Do Until objExecObject.StdOut.AtEndOfStream

   strText = objExecObject.StdOut.ReadAll

Loop

aryText = Split(strText, VbNewLine)

Wscript.Stdout.Write Directory
Wscript.Stdout.Write aryText(ubound(aryText) -2 )
Wscript.Stdout.Write aryText(ubound(aryText) -1)

Open in new window


What is getting is same file number and folder numbers but the bytes are different...I am looking way where i can automatcally verify those...
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
AnuroopsunddCommented:
little Difference can be due to the allocation unit size of the HDD how they are format.
but will be good if you can verify the same.
0
 
Bill PrewCommented:
Just as another fast way to do this, you could do a DIR /S command on both folders and then compare the last two lines, that list number and size of files and folders.  Would be pretty easy to do in a small BAT script, let me know if you want help with that approach.

~bp
0
 
Brent ChallisPrincipal: ITCommented:
Here is a Powershell script that uses a pipeline cmdlet to process all the objects passed in to it to provide a running count of the files and folders found, as well as the total file size.

There are then some lines of code that use this cmdlet to process the directories of interest and determine if they were the same.  I too have found that there is some variation in the total size of all the files.

function Get-FolderDetails
{
    Begin
    {
        $details = New-Object PSObject -Property @{            
        FolderCount = 0
        Filecount = 0
        TotalFileSize = 0
    }
    }
    Process
    {
        if ($_.PSIsContainer)
        {
            $details.FolderCount++
        }
        else
        {
            $details.FileCount++
            $details.TotalFileSize += $_.Length
        }
    }
    End
    {
        Write-Output $details
    }
   
   
}

$original = (dir c:\data\development\powershell -Recurse | Get-FolderDetails)
backup = (dir C:\Backup\Powershell -Recurse | Get-FolderDetails)

if ($original.FolderCount -eq $backup.FolderCount -and $original.FileCount -eq $backup.FileCount -and $original.TotalFileSize -eq $backup.TotalFileSize)
{
    Write-Host "Folder structures match"
}
else
{
    Write-Warning "Folder structures don't match"
    $original
    $backup
}
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now