Announcement

Collapse
No announcement yet.

Script to compare directory size

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script to compare directory size

    Hi,

    I am writing a script to copy files from place to another in preperation for tape backup. I want to compare the source directory to the destination directory to make sure that the files were copied successfully, but I am stuck. Here is the script:
    @echo off
    verify on
    echo Transfer Begins: >> C:\daily.txt
    date /t >>C:\daily.txt
    echo at >>C:\daily.txt
    time /t >>C:\daily.txt

    xcopy \\[DIRECTORY]\*.* \\[DIRECTORY]\BACKUP /s /h /y /c >>C:\daily.txt

    echo Transfer Ends: >> C:\daily.txt
    echo Source Size >>c:\daily.txt
    c:\dl\*.* -N \\[DIRECTORY] >>c:\daily.txt
    echo Destination Size >>c:\daily.txt
    c:\dl\*.* -N \\[DIRECTORY]\backup >>c:\daily.txt
    date /t >>C:\daily.txt
    echo at >>C:\daily.txt
    time /t >>C:\daily.txt
    echo ================================================== ==== >>C:\daily.txt
    type c:\backup.txt >>C:\daily.txt
    del c:\backup.txt
    rename c:\daily.txt backup.txt

    I am using a freeware DOS tool called DL but this only prints the size of the files in the directory, and does not recurse through the subdirectories.

    Does anyone have any ideas? BTW, I am happy to use vbscript to do this if it is necessary.

  • #2
    Re: Script to compare directory size

    See if this would work for you.

    Code:
    strFolderA = "C:\Program Files"            '<---\
    strFolderB = "C:\Documents and Settings"   '<-------- Change the paths to reflect your environment
    strLogFile = "\\server1\share\logfile.txt" '<---/
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolderA = objFSO.GetFolder(strFolderA)
    Set objFolderB = objFSO.GetFolder(strFolderB)
    
    
    
    Set objFile = objFSO.OpenTextFile(strLogFile, 8) '<----------The "8" means you open the file for appending
    
    objFile.WriteLine Now
    
    objFile.WriteLine strFolderA & " is " & FormatNumber(objFolderA.Size / _ 
       (1024*1024),2,,-1) & " MB"
    objFile.WriteLine strFolderB & " is " & FormatNumber(objFolderB.Size / _ 
       (1024*1024),2,,-1) & " MB" 
    
    objFile.Close
    If you need more precision in the number then delete the 2s highlighted in red.
    Regards,
    Jeremy

    Network Consultant/Engineer
    Baltimore - Washington area and beyond
    www.gma-cpa.com

    Comment


    • #3
      Re: Script to compare directory size

      Thanks JeremyW, This is exactly what I was looking for

      Comment


      • #4
        Re: Script to compare directory size

        Excellent! Glad to help.
        Regards,
        Jeremy

        Network Consultant/Engineer
        Baltimore - Washington area and beyond
        www.gma-cpa.com

        Comment

        Working...
        X