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

Copy Multiple files from one Dir into another

Status
Not open for further replies.

denko

Programmer
May 17, 2001
70
US
Hi
How can I copy all files from on e directory into another?
I'm using FileCopy statement but in the loop my pointer to files in first dir does not move. Looks like I'm copying the same file over and over
Thanks
 
Use Dir without parameters to get the next entry that matches the mask:

Dim strFileName As String
Dim strSource As String
Dim strDest As String

strSource = "c:\temp\"
strDest = "c:\temp2\"
strMask = "*.*"
FileName = Dir(strSource & strMask, vbNormal)
While FileName <> &quot;&quot;
FileCopy strSource & FileName, strDest & FileName
FileName = Dir
Wend




Mark
 
Use something like this:
this code here counts all dirs, but you can adapt it to look for archives . add a filecopy command everytime you do the `loop and it should be ok-

if this is not enough for you or need further help:

email me at antoniolondon@yahoo.com good lukkk

'establish search pattern similñar constants exists for
'vbAchive, vbHidden, vbSystem, etc. this one seek directories.:
retornoDir = Dir(srcPath & &quot;*.*&quot;, vbDirectory)

'while dir is not empty
Do While retornoDir <> &quot;&quot;

'skip these ( as in msdos ) as theyre not true dirs.
If retornoDir <> &quot;.&quot; And retornoDir <> &quot;..&quot; Then

If (GetAttr(srcPath & retornoDir) And vbDirectory) = vbDirectory Then

count= count+ 1
End If
End If
retornoDir = Dir 'search next with same pattern as above
Loop
 
And yet another alternative is to create a file collections and then use For Each to enumerate the files

Dim fso, folder, phile, fileCollection
Dim szTargetFolder as String, szDestination as String
Dim szTemp as string

szTargetFolder =&quot;TargetDir&quot;
szDestination = &quot;Destination Dir\&quot;

Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set folder = fso.GetFolder(szFolder)
Set fileCollection = folder.Files


For Each phile In fileCollection
szTemp = szDestination & phile
FileCopy phile, szTemp
Next

HTH,
JC
 
Hello Gurus!
I want to create a simple .VBS file that would
delete *.trc files in a directory if a file is not open by some other process.

I want this .VBS to run under Windows 2000 environment.
Can somebody help with the code?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top