0

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

3
Contributors
7
Replies
8
Views
9 Years
Discussion Span
Last Post by scru
0

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

0

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

Edited by happygeek: fixed formatting

0

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

0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.