Created
May 7, 2022 06:58
-
-
Save PrashantUnity/f76f05492637b76d7e4073a35724b720 to your computer and use it in GitHub Desktop.
Move Files from one folder to another folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using System; | |
namespace ForGeneral | |
{ | |
internal class MoveFiles | |
{ | |
public static void Move() | |
{ | |
try | |
{ | |
// setting path | |
string destinationDirectory = @"C:\Users\priya\OneDrive\Desktop\desti\"; | |
string sourceDirectory = @"C:\Users\priya\OneDrive\Desktop\source"; | |
// getting all subdirectory of sourceDirectory | |
string[] dirs = Directory.GetDirectories(sourceDirectory, "*", SearchOption.TopDirectoryOnly); | |
foreach (string dir in dirs) | |
{ | |
string rootDirectory = dir; | |
string[] Files = Directory.GetFiles(rootDirectory); | |
if (Files.Length == 0) | |
continue; | |
// Moving each file one by one | |
foreach (string file in Files) | |
{ | |
Console.WriteLine($"Currently Moving {file}"); | |
File.Move(file, $"{destinationDirectory}{Path.GetFileName(file)}"); | |
} | |
} | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine("The process failed: {0}", e.ToString()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment