Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2009-02-16
Medium Priority
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
  • 2
LVL 22

Expert Comment

ID: 23658130
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.

Author Comment

ID: 23659657
Hi Paka,

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

LVL 22

Accepted Solution

Paka earned 1000 total points
ID: 23660701
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 = objSub.name
    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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Many of us need to configure DHCP server(s) in their environment. We can do that simply via DHCP console on server or using MMC snap-in on each computer with Administrative Tools installed in a network. But what if we have to configure many DHCP ser…
Learn about cloud computing and its benefits for small business owners.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

578 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