Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / May 2008

Tip: Looking for answers? Try searching our database.

copy files by name patterns with wildcard

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stefi - 30 May 2008 07:43 GMT
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
Gary Keramidas - 30 May 2008 08:06 GMT
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.

Signature

Gary

> Hi All,
>
[quoted text clipped - 7 lines]
> Thanks,
> Stefi
Stefi - 30 May 2008 08:18 GMT
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:

> 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
[quoted text clipped - 13 lines]
> > Thanks,
> > Stefi
stefan onken - 30 May 2008 08:21 GMT
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

> Hi All,
>
[quoted text clipped - 7 lines]
> Thanks,
> Stefi
Stefi - 30 May 2008 08:56 GMT
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,
> you could use FSO:
[quoted text clipped - 26 lines]
> > Thanks,
> > Stefi
stefan onken - 30 May 2008 09:40 GMT
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

> 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.
Rick Rothstein (MVP - VB) - 30 May 2008 09:57 GMT
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

> hi Stefi,
> i used the code from my code collection, where i copied some
[quoted text clipped - 16 lines]
>> By the way, what does the $ sign means in Dir$ function? XL Help doesn't
>> mention this format.
Stefi - 30 May 2008 10:53 GMT
Thanks Rick for the explanation!
Stefi

„Rick Rothstein (MVP - VB)” ezt írta:

> 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
[quoted text clipped - 28 lines]
> >> By the way, what does the $ sign means in Dir$ function? XL Help doesn't
> >> mention this format.
stefan onken - 30 May 2008 10:56 GMT
thank you!

stefan

On 30 Mai, 10:57, "Rick Rothstein \(MVP - VB\)"
<rick.newsNO.S...@NO.SPAMverizon.net> wrote:
> 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
[quoted text clipped - 7 lines]
>
> Rick
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.