467,075 Members | 1,097 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,075 developers. It's quick & easy.

copy files

I want to be able to copy a directory of files (all .HTM files) from a
network drive to a local drive on the machine c:\HTMFiles , How can i do
that?

I tried File.Copy(source, dest) but i need to put the file name in the dest
section. I just want to copy the entire directory since I don't know all the
file names just the extensions. Would
File.Copy("\servername\folder", "c:\\HTMFiles\*.HTM") work or no?

thx
Nov 15 '05 #1
  • viewed: 7949
Share:
11 Replies
Mike <cs*********@sbcglobal.net> wrote:
I want to be able to copy a directory of files (all .HTM files) from a
network drive to a local drive on the machine c:\HTMFiles , How can i do
that?

I tried File.Copy(source, dest) but i need to put the file name in the dest
section. I just want to copy the entire directory since I don't know all the
file names just the extensions. Would
File.Copy("\servername\folder", "c:\\HTMFiles\*.HTM") work or no?


No, I wouldn't expect it to. File.Copy expects the name of *a* file.
You need something like Directory.GetFiles to find out which files to
copy, and then copy each of them in turn.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
So i can't just copy all the files from one spot to another?
I need each file name? If so that won't work for me since the file names
will be different everytime

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Mike <cs*********@sbcglobal.net> wrote:
I want to be able to copy a directory of files (all .HTM files) from a
network drive to a local drive on the machine c:\HTMFiles , How can i do
that?

I tried File.Copy(source, dest) but i need to put the file name in the dest section. I just want to copy the entire directory since I don't know all the file names just the extensions. Would
File.Copy("\servername\folder", "c:\\HTMFiles\*.HTM") work or no?


No, I wouldn't expect it to. File.Copy expects the name of *a* file.
You need something like Directory.GetFiles to find out which files to
copy, and then copy each of them in turn.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #3
Mike <cs*********@sbcglobal.net> wrote:
So i can't just copy all the files from one spot to another?
Not in one call to File.Copy, no.
I need each file name? If so that won't work for me since the file names
will be different everytime


That's why you use Directory.GetFiles to find out what the files are
first...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
So since I just need only the files with .HTM extensions, i just can't use a
wildcard?
File.Copy("location\*.htm)


"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Mike <cs*********@sbcglobal.net> wrote:
So i can't just copy all the files from one spot to another?


Not in one call to File.Copy, no.
I need each file name? If so that won't work for me since the file names
will be different everytime


That's why you use Directory.GetFiles to find out what the files are
first...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #5
Mike <cs*********@sbcglobal.net> wrote:
So since I just need only the files with .HTM extensions, i just can't use a
wildcard?


No, you can't. File.Copy copies *a file*, not a whole load of files.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6
OK thanks for your information and help, so it appears that i can't automate
this process of my app then. thanks again
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Mike <cs*********@sbcglobal.net> wrote:
So since I just need only the files with .HTM extensions, i just can't use a wildcard?


No, you can't. File.Copy copies *a file*, not a whole load of files.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #7
Mike <cs*********@sbcglobal.net> wrote:
OK thanks for your information and help, so it appears that i can't automate
this process of my app then. thanks again


Yes, you can. Very easily. Just not in one line of code.

I repeat:

Use Directory.GetFiles to find the list of HTML files.
Go through each of the files it returns, and call File.Copy with it.

What's the matter with that solution?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #8
Actually i just tried that it i get, "can't a files that already exsist"
when i try the file.copy piece
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Mike <cs*********@sbcglobal.net> wrote:
OK thanks for your information and help, so it appears that i can't automate this process of my app then. thanks again


Yes, you can. Very easily. Just not in one line of code.

I repeat:

Use Directory.GetFiles to find the list of HTML files.
Go through each of the files it returns, and call File.Copy with it.

What's the matter with that solution?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #9
Mike <cs*********@sbcglobal.net> wrote:
Actually i just tried that it i get, "can't a files that already exsist"
when i try the file.copy piece


Then you presumably either want the version that will overwrite
existing files, or check whether or not the destination file exists
first, and ignore that file if so.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #10
were can i find a snippet of code or an example that does this? I want to
see verify that my syntax is correct. I'm getting a new error everytime I
run the app
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Mike <cs*********@sbcglobal.net> wrote:
Actually i just tried that it i get, "can't a files that already exsist"
when i try the file.copy piece


Then you presumably either want the version that will overwrite
existing files, or check whether or not the destination file exists
first, and ignore that file if so.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #11
Mike <cs*********@sbcglobal.net> wrote:
were can i find a snippet of code or an example that does this? I want to
see verify that my syntax is correct. I'm getting a new error everytime I
run the app


Why don't you write a test console app then? That way you won't need to
go through much to find the problems.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Wayne Wengert | last post: by
2 posts views Thread by Steve Franks | last post: by
8 posts views Thread by luis molina Micasoft | last post: by
13 posts views Thread by jim | last post: by
1 post views Thread by =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post: by
1 post views Thread by =?Utf-8?B?UmFkZW5rb19aZWM=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.