Solved

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

Posted on 2012-04-07
6
1,276 Views
Last Modified: 2012-05-23
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
Comment
Question by:principiamanagement
6 Comments
 
LVL 17

Expert Comment

by:Anuroopsundd
ID: 37819595
$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
 
LVL 3

Expert Comment

by:suresh_boga
ID: 37819729
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
 

Author Comment

by:principiamanagement
ID: 37820470
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 17

Expert Comment

by:Anuroopsundd
ID: 37820476
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
 
LVL 51

Accepted Solution

by:
Bill Prew earned 250 total points
ID: 37823552
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
 
LVL 8

Assisted Solution

by:bchallis
bchallis earned 250 total points
ID: 37854490
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

Do email signature updates give you a headache?

Do you feel like you are constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

Join & Write a Comment

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
Know what services you can and cannot, should and should not combine on your server.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now