Step 1. Add following namespace
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();
-
-
- string str = "Your Destination"+file.ToString(),Replace("Your Path");
- if (!File.Exists(str))
- {
- File.Copy(file , str);
- }
- }
- }
Here is a detailed tutorial on file class,
Working with Files Using File Class In C#