Step 1. Add following namespace
- using System.IO;
Step 2. We can use File.Copy method to copy a file from current location to a new location. We can also change the file name as well. The following code snippet reads all files in Your Path folder.
Note: Replace "Your Path" with the full path of your directory you want to move and "Your Destination" with your new full path.
- public void readfiles()
- {
- string[] filePaths = Directory.GetFiles("Your Path");
- foreach (var filename in filePaths)
- {
- string file = filename.ToString();
- //Do your job with "file"
- string str = "Your Destination"+file.ToString(),Replace("Your Path");
- if (!File.Exists(str))
- {
- File.Copy(file , str);
- }
- }
- }


aaditya mauryaPosted Sep 30, 2021, 1:16 AM EDT
This work only in same directory .
Bhargav BattinaPosted Mar 27, 2020, 2:02 AM EDT
(cannot use constructor arguments in declaration using replace)
Bhargav BattinaPosted Mar 27, 2020, 2:01 AM EDT
Hi I'm getting error with replace method
Mohamedasiq ShajahanPosted Aug 27, 2019, 3:40 AM EDT
Why You have mentioned comma instead of Dot, for Replacing the string?
Ganesan KPosted Jan 4, 2016, 2:33 AM EST
Hi, how to choose the folders in UI, in html5 controls we choose the files only not a folder. Thanks.
Sridhar MahendrakarPosted Apr 23, 2015, 3:43 PM EDT
Thank u...