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

How to copy multiple files

Status
Not open for further replies.

gmagerr

Technical User
Aug 11, 2001
323
US
Hi all
Can someone please show me how i would copy several files with different names from a directory to another? the files are different names and types. Here's the code i have that will copy one file. thanks

Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const OverWriteExisting = True
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objDomain = getObject("LDAP://rootDse")
strDomain = objDomain.Get("dnsHostName")

strUser = WshNetwork.UserName
strHome = "\\sm-athena\Home\"
strHomeFolder = strHome & strUser

If Not objFSO.FolderExists(strHomeFolder) Then

objFSO.CreateFolder strHomeFolder
     If Err.Number <> 0 Then
     On Error GoTo 0
     Wscript.Echo "Cannot create: " & strHomeFolder
     End If
On Error GoTo 0
End If

strSource = "C:\Program Files\lotus\notes\data\Names.nsf"
strDest = strHomeFolder & "\"
objFSO.CopyFile strSource, strDest, OverWriteExisting

Set objFSO = Nothing
 
A starting point:
strSource = "C:\Program Files\lotus\notes\data\[!]*.*[/!]"
strDest = strHomeFolder & "\"
objFSO.CopyFile strSource, strDest, OverWriteExisting

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks PHV I don't want to copy everything in the folder, just 5 or 6 files. they have different names and extensions. Any way to do that?
 
Something like this ?
strSource = "C:\Program Files\lotus\notes\data\"
strDest = strHomeFolder & "\"
For Each strFileName In Array("file1.ext1","file2.ext2","file3.ext3")
objFSO.CopyFile strSource & strFileName, strDest, OverWriteExisting
Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Along the same lines of what PHV put, you could make your array be a collection of patterns to look for with the wild card.

Code:
For Each strFileName In Array("startwith*.doc","somename.*","*endwith.doc")
  objFSO.CopyFile strSource & strFileName, strDest, OverWriteExisting
Next

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Man! you guys are GOOD!!! ok last thing. How about sub folders? How would i get files from a sub folder? I need to copy notes.ini from C:\Program Files\lotus\notes\
and Names.nsf and Bookmarks.nsf from C:\Program Files\lotus\notes\data\ Thanks a million.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top