473,756 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(sourc e, 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("\ser vername\folder" , "c:\\HTMFiles\* .HTM") work or no?

thx
Nov 15 '05 #1
11 8258
Mike <cs*********@sb cglobal.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(sourc e, 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("\ser vername\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.GetFi les to find out which files to
copy, and then copy each of them in turn.

--
Jon Skeet - <sk***@pobox.co m>
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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Mike <cs*********@sb cglobal.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(sourc e, 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("\ser vername\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.GetFi les to find out which files to
copy, and then copy each of them in turn.

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

Nov 15 '05 #3
Mike <cs*********@sb cglobal.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.GetFi les to find out what the files are
first...

--
Jon Skeet - <sk***@pobox.co m>
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("loca tion\*.htm)


"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Mike <cs*********@sb cglobal.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.GetFi les to find out what the files are
first...

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

Nov 15 '05 #5
Mike <cs*********@sb cglobal.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.co m>
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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Mike <cs*********@sb cglobal.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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #7
Mike <cs*********@sb cglobal.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.GetFi les 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.co m>
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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Mike <cs*********@sb cglobal.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.GetFi les 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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #9
Mike <cs*********@sb cglobal.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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1639
by: Wayne Wengert | last post by:
I am using VSNET 2003 to build an ASP.NET/VB set of pages. There are currently about a dozen aspx pages. When I make even a minor change to one page I currently rebuild the solution, copy the project files to a copy directory on my local wwwroot and then FTP all those files and directories to my ISP account to be able to see the change on my web site. This is a lot of data to FTP every time (the bin directory alone is close to 4MB) Is...
3
2189
by: Johnny | last post by:
Hi, I have created an ASP.NET application (let's call it FooBar) with VS.NET on my local machine, residing in http://localhost/FooBar. Deploying it to another folder on my machine works well with FrontPage Server Extensions, but I don't manage to deploy the application to my web provider http root folder. When I run Copy Project, I get an error message just saying 'Unable to create Web project 'myname'. Not found.'.
2
1646
by: Steve Franks | last post by:
The Copy Web tool provided with VS.NET 2005 is very convenient. However every once in a while it seems to think the files on the remote server have changed, which they have not. Then when I use the Copy Web Site feature of Copy Web to just copy the entire web site over, it thinks it has to re-upload the entire site which takes a very long time - when in fact those files on the remote have not changed. Does anyone know why this occurs...
5
21029
by: DraguVaso | last post by:
Hi, I'm looking for a way to Copy and Paste Files to the clipboard. I found a lot of articles to copy pieces of text and bitmaps etc, but nog whole files. Whay I need is like you have in windows explorer: when you do a right-click on a file and choose Copy, and than paste it somewhere in my application and vice versa.
8
2935
by: luis molina Micasoft | last post by:
it seems that when i do file.copy the svchost.exe is hanged, i mean if i make 40 threads of file.copy , 40 copys of files at same time the system is going down and stop responding, this is when i'm working with cifs (shares). there is another solution to copy files than file.copy in .net?
1
4154
by: dkmarni | last post by:
Hi, I am trying to do this perl script, but not able to complete it successfully. Here is the description what the script has to do.. Accept two and only two command line arguments. Again, these will be the names of two directories. This time, make sure that the "sending" directory exists (and is, indeed, a directory). Make sure that the "receiving" directory exists, and if not, create it. Then, copy files from the sending directory to...
13
2618
by: jim | last post by:
Is there a way (using VB.Net or C#) to copy open or locked files? Thanks! jim
1
3897
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
Using .NET 2.0 is it more efficient to copy files to a single folder versus spreading them across multiple folders. For instance if we have 100,000 files to be copied, Do we copy all of them to a single folder called 'All Files' Do we spread them out and copy them to multiple folders like Folder 000 - Copy files from 0 to 1000 Folder 001 - Copy files from 1000 to 2000 Folder 002 - Copy files from 2000 to 2999
1
4299
by: =?Utf-8?B?UmFkZW5rb19aZWM=?= | last post by:
I am using standard File.Copy(source,dest,true) method in C# and I have problem with copying large number of files. Here is my code: foreach (FileInfo file in files) { File.Copy(file.FullName,destPath+ "\\" + file.Name, true); } This code copies only 5 or 10 files but in "files" collection there is 60 files.
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10034
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9843
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8713
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.