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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy files and path 1

Status
Not open for further replies.

edms

IS-IT--Management
Dec 16, 2002
8
0
0
AU
I am writing a script to backup all word docs on a users PC to a mapped network drive. My problem is I want to retain the directory structure. ie if a doc file was found at C:\documents\sales\june\monthly.doc then it should be copied to H:\documents\sales\june\monthly.doc, creating the directories on the fly.

Is there an easy way to do this? at the moment my script copies all files into one directory, so files with the same name get overwritten.
 
Why not simply use something like this ?
Set sh = CreateObject("WScript.Shell")
sh.Run "XCOPY /S/R/Y C:\documents\*.doc H:\documents\", 1, True

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I need to backup a number of extentions, .doc .xls .ppt .pdf .mdb .pst and more may be added, my current script allows me to search for all these extentions at once, the xcopy script would need to be run for each extention and would most likely take considerablly longer to execute

 
So, take a look at the FolderExists and CreateFolder methods of the FileSystemObject object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
how do you create multiple folders in a path ie if I try to create C:\documents\sales\june\ with CreateFolder I get an error, I would first need to create c:\documents then c:\documents\sales and then c:\documents\sales\june. Is there an easy way?
 
Provided you have a global instance of the FileSystemObject named fso, you may consider a procedure creating all the folder hierarchy of a given file pathname:
Sub myCreateFolder(strPath)
tmpArr = Split(strPath, "\")
tmpPath = tmpArr(0)
For i = 1 To UBound(tmpArr)
If Not fso.FolderExists(tmpPath) Then
fso.CreateFolder tmpPath
End If
tmpPath = tmpPath & "\" & tmpArr(i)
Next
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top