Solved

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

Posted on 2012-04-07
6
1,346 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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 54

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:Brent Challis
Brent Challis 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 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