copy files

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

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
 
Mike said:
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.
 
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
 
Mike said:
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...
 
So since I just need only the files with .HTM extensions, i just can't use a
wildcard?
File.Copy("location\*.htm)
 
Mike said:
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.
 
OK thanks for your information and help, so it appears that i can't automate
this process of my app then. thanks again
 
Mike said:
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?
 
Actually i just tried that it i get, "can't a files that already exsist"
when i try the file.copy piece
 
Mike said:
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.
 
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
 
Mike said:
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.
 
Back
Top