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, 5:16 AM
This work only in same directory .
Bhargav BattinaPosted Mar 27, 2020, 6:02 AM
(cannot use constructor arguments in declaration using replace)
Bhargav BattinaPosted Mar 27, 2020, 6:01 AM
Hi I'm getting error with replace method
Mohamedasiq ShajahanPosted Aug 27, 2019, 7:40 AM
Why You have mentioned comma instead of Dot, for Replacing the string?
Ganesan KPosted Jan 4, 2016, 7:33 AM
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, 7:43 PM
Thank u...