PC Review


Reply
Thread Tools Rate Thread

copy files by name patterns with wildcard

 
 
Stefi
Guest
Posts: n/a
 
      30th May 2008
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

 
Reply With Quote
 
 
 
 
Gary Keramidas
Guest
Posts: n/a
 
      30th May 2008
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" <(E-Mail Removed)> wrote in message
news:6A2C8638-678F-4071-BD09-(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Stefi
Guest
Posts: n/a
 
      30th May 2008
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" <(E-Mail Removed)> wrote in message
> news:6A2C8638-678F-4071-BD09-(E-Mail Removed)...
> > 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
> >

>
>
>

 
Reply With Quote
 
stefan onken
Guest
Posts: n/a
 
      30th May 2008
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 <St...@discussions.microsoft.com> 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


 
Reply With Quote
 
Stefi
Guest
Posts: n/a
 
      30th May 2008
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 <St...@discussions.microsoft.com> 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

>
>

 
Reply With Quote
 
stefan onken
Guest
Posts: n/a
 
      30th May 2008
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 <St...@discussions.microsoft.com> 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.



 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      30th May 2008
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" <(E-Mail Removed)> wrote in message
news:7cbd5b67-41b7-4ecd-8744-(E-Mail Removed)...
> 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 <St...@discussions.microsoft.com> 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.

>
>


 
Reply With Quote
 
Stefi
Guest
Posts: n/a
 
      30th May 2008
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" <(E-Mail Removed)> wrote in message
> news:7cbd5b67-41b7-4ecd-8744-(E-Mail Removed)...
> > 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 <St...@discussions.microsoft.com> 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.

> >
> >

>
>

 
Reply With Quote
 
stefan onken
Guest
Posts: n/a
 
      30th May 2008
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
> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Searching binary files for patterns? Joseph N. Stackhouse Microsoft VB .NET 1 20th Nov 2009 05:14 PM
Can you recommend a book about design patterns? (factory patterns, singleton patterns etc) Joakim Olesen Microsoft Dot NET 4 4th Jan 2005 07:17 AM
wildcard copy Mark Microsoft Dot NET Framework 2 27th May 2004 12:41 AM
RE: Copy to wildcard =?Utf-8?B?Y2hyaXM=?= Microsoft Excel Programming 2 21st May 2004 07:01 PM
How to copy directories using a wildcard Patrick Microsoft Windows 2000 CMD Promt 1 5th Nov 2003 09:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:27 AM.