copy files by name patterns with wildcard

  • Thread starter Thread starter Stefi
  • Start date Start date
S

Stefi

Hi All,

Can I copy files via VBA by name patterns with wildcard characters like in
DOS:
copy filename*.ext ...
I know how to find file names matching the pattern and copy them
individually (in a loop), my question is that can it be done with a single
statement?

Thanks,
Stefi
 
i don't think there's any built in way, but someone that knows windows scripting
should know how to. the filecopy statement works with single files as far as i
know.

you say you know how to loop, so i didn't post any other solutions.
 
Thanks Gary, now I have two options:
1. Copy in a loop.
2. Wait for a response from a windows scripting expert.

Regards,
Stefi

„Gary Keramidas†ezt írta:
 
hi Stefi,
you could use FSO:

Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile "D:\test\filename*.ext", "D:\test\test\"

or

strPath = "D:\test\"
strNewPath = "D:\test\test\"
file = Dir$(strPath & "filename*.ext")
Do While file <> ""
FileCopy strPath & file, strNewPath & file
file = Dir$()
Loop

bye
stefan
 
Thanks Stefan, fso.CopyFile is the very method I was looking for, it works!
By the way, what does the $ sign means in Dir$ function? XL Help doesn't
mention this format.

Regards,
Stefi


„stefan onken†ezt írta:
 
hi Stefi,
i used the code from my code collection, where i copied some
codefragment with Dir$ a while ago.
so, I`m not sure if this is correct:
you can write
Dim strText As String
also
Dim strText$

therefore Dir$ forces Dir to return a String, but it does it without
the $ as well.
thank you for making me thinking about it (and changing my code
collection ;)

stefan
 
You are partially correct. For all String functions (Dir, Mid, Format,
etc.), if you include the $ sign at the end of the function name, that
function will return a value of type String. However, if you don't include
the $ sign, the function will return a Variant with a sub-type of String.
The only time including the $ sign will really matter is if you use the
String function in a very large loop... Variants take up more memory (which
probably won't matter if you are assigning the output to a variable declared
as a String) and are slower to work with, so (in a large loop) the this
slowness will become measurable.

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top