Click here to Skip to main content
15,917,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All :

For Examp :

My List1 Have 10 Item Of Source Path
My List2 Have 10 Item Of Target Path

How To Copy Source Directorys To Target Path ?(C#.Net)

Thanks...

What I have tried:

My Source :

C#
//Get All .Tar Files in All Sub Folders
            string[] files = System.IO.Directory.GetFiles(@"E:\LOG", "*.tar", SearchOption.AllDirectories);

               //Rename All Oldfile.tar To Oldfile.1.rar
            foreach (string s in files)
            {

                listBox1.Items.Add(Path.GetFullPath(s));
                
                System.IO.File.Move(Path.GetFullPath(s).ToString(), Path.GetFullPath(s) + "1.rar".ToString());

            }


            ///
            string[] files1 = System.IO.Directory.GetFiles(@"E:\LOG", "*.rar", SearchOption.AllDirectories);

            listBox1.Items.Clear();
            foreach (string ss in files1)
            {

               
                listBox2.Items.Add(Path.GetFullPath(ss));
            }
Posted
Comments
[no name] 24-Oct-16 17:50pm    
Where is your code for copying files?
siva966 25-Oct-16 3:24am    
you want to rename a file in target? For "E:\LOG\dd.tar" to "E:\LOG\dd1.rar"?

1 solution

C#
string[] files = System.IO.Directory.GetFiles(@"E:\LOG", "*.tar", SearchOption.AllDirectories);

 //Rename All Oldfile.tar To Oldfile.1.rar
 foreach (string s in files)
 {

 listBox1.Items.Add(Path.GetFullPath(s));
 FileInfo f = new FileInfo(s);
 File.Copy(Path.GetFullPath(s).ToString(), 
  f.DirectoryName + @"\" + f.Name.Replace(f.Extension, "") + ".1.rar".ToString());

 }

         
 string[] files1 = System.IO.Directory.GetFiles(@"E:\LOG", "*.rar", SearchOption.AllDirectories);

          listBox1.Items.Clear();
          foreach (string ss in files1)
          {


              listBox2.Items.Add(Path.GetFullPath(ss)); 
          }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900