We help IT Professionals succeed at work.

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

amyassein
amyassein asked
on
Medium Priority
321 Views
Last Modified: 2012-05-06
Hi,

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.

Yassein
Comment
Watch Question

Commented:
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

Commented:
Hi Paka,

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

Regards,
Yassein
Commented:
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
next
  
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.