Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default copy files by name patterns with wildcard

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default copy files by name patterns with wildcard

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.

--


Gary


"Stefi" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default copy files by name patterns with wildcard

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
know.

you say you know how to loop, so i didn't post any other solutions.

--


Gary


"Stefi" wrote in message
...
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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default copy files by name patterns with wildcard

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

On 30 Mai, 08:43, Stefi wrote:
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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default copy files by name patterns with wildcard

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:

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

On 30 Mai, 08:43, Stefi wrote:
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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default copy files by name patterns with wildcard

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

On 30 Mai, 09:56, Stefi wrote:
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.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default copy files by name patterns with wildcard

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


"stefan onken" wrote in message
...
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

On 30 Mai, 09:56, Stefi wrote:
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.




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default copy files by name patterns with wildcard

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
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


"stefan onken" wrote in message
...
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

On 30 Mai, 09:56, Stefi wrote:
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.





  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default copy files by name patterns with wildcard

thank you!

stefan

On 30 Mai, 10:57, "Rick Rothstein \(MVP - VB\)"
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
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Attaching files to emails using a wildcard Andrew@Telstra Excel Programming 4 July 13th 07 02:26 AM
using wildcard characters for filenames in externally linked files Harold Good Excel Discussion (Misc queries) 0 June 27th 06 03:40 AM
check mutiple files with wildcard name and tally to differnt xls f JCanyoneer Excel Programming 2 May 2nd 06 05:58 PM
Copy to wildcard chris Excel Programming 2 May 21st 04 07:01 PM
Using wildcard for checking whether files are open [email protected] Excel Programming 1 July 30th 03 06:47 PM


All times are GMT +1. The time now is 03:07 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"