ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   copy files by name patterns with wildcard (https://www.excelbanter.com/excel-programming/411751-copy-files-name-patterns-wildcard.html)

Stefi

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


Gary Keramidas

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




Stefi

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





stefan onken

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



Stefi

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




stefan onken

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.




Rick Rothstein \(MVP - VB\)[_2028_]

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.





Stefi

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.






stefan onken

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





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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com