How can i copy home folders to another server based on size using a script?

Posted on 2009-02-16
Last Modified: 2012-05-06

I need a way (whether through scripts or whatever) to copy home folders that are less than 500 MB. For example, when i double click on a script, it contacts the server where home folders reside and copy only folders that are less than 500MB to another server.

I beleive that such script exist in this world but i couldn't find it in google, yahoo ..etc.

Of course, robocopy.exe will not do anything like this. It only copies folders from location to another location using basic switches and it lacks these detailed calculations.

Kindly advise.

Question by:amyassein
    LVL 22

    Expert Comment

    Get another look at RoboCopy - specifically the /min and /max command line options.  These command line options will allow you to exclude copying files that are larger than or smaller than specified values.  In your case, you'd use the /max:5000000000 option.
    LVL 1

    Author Comment

    Hi Paka,

    Thanks for the quick response. However, these options applies on files only. What about folders?

    LVL 22

    Accepted Solution

    Sorry - I misread your post - too many fires going on here.  Here's some vbscript that should get you started.  Make sure you change the following constants in the beginning:
    const folderRoot = "c:\" '(change to your home folder location path)
    const folderRootDest = "x:\" (change to your backup location path)

    The actual command to execute the xcopy is currently commented out.  It will display a message box with the command that would execute.  After it is tested, just comment out the MsgBox objCommand and uncomment out the 'WshShell.Run command.

    Credit for the the recursion code comes from SmufHell at Tek Tips.
    option explicit
    const sizeLimit = 500
    const folderRoot = "c:\"
    const folderRootDest = "x:\"
    Dim objFSO, objFolder, objSub, colSub, r 
    dim folderSize
    dim sourceName, destName
    dim objCommand
    set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
    set objFolder = objFSO.GetFolder(folderRoot)
    set colSub = objFolder.subfolders
    for Each objsub in colsub
      ShowSub objsub, r
    Function ShowSub (objsub, r)
        sourceName =
        folderSize = objsub.Size /1024\1024
    if folderSize >= sizeLImit then
      wscript.echo sourceName & " (and subfolders) is greater than " & sizeLimit & " MB"
      objCommand = "xcopy " & Chr(34) & folderRoot & sourceName & Chr(34) & " " & Chr(34) & folderRootDest & sourceName & Chr(34) & " /s" 
      MsgBox objCommand
      'WshShell.Run objCommand, 1, True
    end if
        r = r+1
    End Function

    Open in new window


    Featured Post

    IT, Stop Being Called Into Every Meeting

    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!

    Join & Write a Comment

    This may not be a text book method to resolve VSS backup issues but it seemed to have worked on few of the Windows 2003 servers we had issues while performing a Volume Shadow Copy backup. If you have issues while performing a shadow copy backup usin…
    A quick step-by-step overview of installing and configuring Carbonite Server Backup.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    754 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

    18 Experts available now in Live!

    Get 1:1 Help Now