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

FileCopy Help Needed 1

Status
Not open for further replies.

rss01

Technical User
Oct 10, 2001
125
US
I want to copy files from one directory to another. I can use the FileCopy command and get this to work but I have to hard code each file name and its path. Is there away to use wild cards to do something like this??

This code works
FileCopy "C:\Temp\file.xls", "F:\completed\file.xls"

This code does not. But this is what I want to do
FileCopy "C:\Temp\*.xls","F:\completed\"
 
no, but you can make an function, that stores all the names of xls files to an array then use concatination.

eg.

use a for and:

FileCopy FileCopy "C:\Temp\" & myfile(i)& ".xls","F:\completed\" & myfile(i) "& xls

or... you can use an array to store the entire string..

eg.
FileCopy FileCopy "C:\Temp\" & myfile(i),"F:\completed\" & myfile(i)

I believe this will work ;-) Cruz'n and Booz'n always.
This post shows what little I do at work.
 
Something like:

Sub CopyMyFiles()
Dim ExtString As String
Dim MyFileName As String
ExtString = ".xls" 'change for another type
myFileName = Dir("C:\Temp\")
If MyFileName <> &quot;&quot; Then
While MyFileName <> &quot;&quot;
If Right(MyFileName)=ExtString Then
FileCopy &quot;C:\Temp\&quot; & myfilename,&quot;F:\completed\&quot; & MyFileName
'Kill &quot;C:\Temp\&quot; & MyFileName 'uncomment to delete the file
End If
MyFileName = Dir
Wend
End If

Good luck

[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
I had to add a string length to

If Right(MyFileName,4)=ExtString Then

This worked great. Thats for the help

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top