Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Attaching files to emails using a wildcard | Excel Programming | |||
using wildcard characters for filenames in externally linked files | Excel Discussion (Misc queries) | |||
check mutiple files with wildcard name and tally to differnt xls f | Excel Programming | |||
Copy to wildcard | Excel Programming | |||
Using wildcard for checking whether files are open | Excel Programming |