hai ,
i have a sever in that thare are Z and E drives are there.i have .bak files in Z drive.i need to copy all .bak files into E drive by using c#.net .
plz help me........
thanks in advance....
regards
chinnareddy
hai ,
i have a sever in that thare are Z and E drives are there.i have .bak files in Z drive.i need to copy all .bak files into E drive by using c#.net .
plz help me........
thanks in advance....
regards
chinnareddy
These Classes in the System.IO Namespace will help:
Directory
File
Specifically, you need:
Directory.GetFiles("Z:\\", "*.bak");
Which will return a string[] array. Simply loop through this array and call File.Copy
a
hai scru,
string[] files= Directory.GetFiles("Z:\\", "*.bak");
foreach (string file in files)
{
File.Copy(file, @"E:\",true);
}
but it giving the error like this Could not find a part of the path 'E:\'
.
thanks in advance
chinna
running as a service?
no i am not running service.
just i write the code in button_click
but i want to copy the files in the server.
do u have any idea plz forward me..
thanks
I believe its trying to tell you the filename is missing. Which it is, you just give "E:\" there is no filename.
Just checked, yep, thats exactly it.
Yeh what LizR said, only let me break it down more:
The File.Copy method doesn't want a destination directory, it wants a destination file. So you have to do this in the loop:
string destinationFile = Path.GetFileName(file);
File.Copy(file, "E:\\" + destinationFile, true);
Hope this helps.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.