Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2012-04-07
6
Medium Priority
?
1,473 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Are You Ready for GDPR?

With the GDPR deadline set for May 25, 2018, many organizations are ill-prepared due to uncertainty about the criteria for compliance. According to a recent WatchGuard survey, a staggering 37% of respondents don't even know if their organization needs to comply with GDPR. Do you?

 
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 57

Accepted Solution

by:
Bill Prew earned 750 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 750 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

688 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