• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

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

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
0
amyassein
Asked:
amyassein
  • 2
1 Solution
 
PakaCommented:
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.
0
 
amyasseinAuthor Commented:
Hi Paka,

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

Regards,
Yassein
0
 
PakaCommented:
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

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now