Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving folders and files

Status
Not open for further replies.

larsjuhl

IS-IT--Management
Oct 24, 2001
88
DK
Hi there,
I want to move all files and folders when a user logs on.
for an example when they log on I want to copy all files and folders from the users G: driver to their H: drive

I have this script from ms:

Const OverWriteFiles = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFolder "C:\Scripts" , "C:\FSO" , OverWriteFiles

but this wont do from g: to H: I have to specify a folder and that is not enough I need the whole drive, this is for 40 users and their homedrive I need to move so I cannot use UNC path since every user has a different homedrive share on server.

anyone who has a script ?

I very new to script and hoping for a fast solution.. :eek:)

thx in advance
 
you're saying this won't work for you?

Const OverWriteFiles = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFolder "G:\userFolderName" , "H:\userFolderName" , OverWriteFiles



=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Hi jeff,
no that will work but this wont

Const OverWriteFiles = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFolder "G:\" , "H:\" , OverWriteFiles

I dont have a folder only the whole drive

thanks
 
Hello,

Is it great fun, scripting?

If you use
objFSO.CopyFolder "G:\*" , "H:\" , OverWriteFiles

you should get all the subfolders under the root copied all right, but not the files directly under the root.

So in any case, you need a two-step process. I would prefer in this case deal directly with the folder object.

Code:
'-----
Option Explicit
Dim objFSO, objRoot, objFile, objSubfolder
Const OverWriteFiles = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objRoot=objFSO.GetFolder("G:")
For Each objFile In objRoot.Files
     objFile.Copy "H:\", OverWriteFiles
Next
For Each objSubfolder In objRoot.Subfolders
     objSubfolder.Copy "H:\", OverWriteFiles
Next
Set objSubfolder=Nothing
Set objFile=Nothing
Set objRoot=Nothing
Set objFSO=Nothing
'-----

regards - tsuji
 
Might be easier to Shell-run "xcopy".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top