CSHARP
move file from one folder to another c#
//take all files of main folder to folder model_RCCMrecTransfered
string rootFolderPath = @"F:/model_RCCMREC/";
string destinationPath = @"F:/model_RCCMrecTransfered/";
string filesToDelete = @"*_DONE.wav"; // Only delete WAV files ending by "_DONE" in their filenames
string[] fileList = System.IO.Directory.GetFiles(rootFolderPath, filesToDelete);
foreach (string file in fileList)
{
string fileToMove = rootFolderPath + file;
string moveTo = destinationPath + file;
//moving file
File.Move(fileToMove, moveTo);
move files from one directory to another using c#
using System.IO;
string rootDirectory = @"C:UsersUSERFolder1";
string destinationDirectory = @"C:UsersUSERFolder2";
string[] Files = Directory.GetFiles(rootDirectory);
foreach (string file in Files) {
File.Move(file, $"{destinationDirectory}{Path.GetFileName(file)}");
}
c# move files from one folder to another
/// <summary>
/// Move files and Directory
/// </summary>
/// <param name="fromPath"></param>
/// <param name="toPath"></param>
/// <param name="addDateTimeSubFolder"></param>
Using System.IO;
public static void Move(string fromPath, string toPath, bool addDateTimeSubFolder)
{
if (string.IsNullOrEmpty(fromPath))
{
throw new ArgumentException($"'{nameof(fromPath)}' cannot be null or empty", nameof(fromPath));
}
if (string.IsNullOrEmpty(toPath))
{
throw new ArgumentException($"'{nameof(toPath)}' cannot be null or empty", nameof(toPath));
}
if (addDateTimeSubFolder)
{
var subFolder = DateTime.Now.ToString("YYYYMMDD");
Directory.Move(fromPath, toPath + @"" + subFolder);
}
else
{
Directory.Move(fromPath, toPath);
}
}
move file from one folder to another c#
//take all files of main folder to folder model_RCCMrecTransfered
string rootFolderPath = @"F:/model_RCCMREC/";
string destinationPath = @"F:/model_RCCMrecTransfered/";
string filesToDelete = @"*_DONE.wav"; // Only delete WAV files ending by "_DONE" in their filenames
string[] fileList = System.IO.Directory.GetFiles(rootFolderPath, filesToDelete);
foreach (string file in fileList)
{
string fileToMove = rootFolderPath + file;
string moveTo = destinationPath + file;
//moving file
File.Move(fileToMove, moveTo);
move files from one directory to another using c#
using System.IO;
string rootDirectory = @"C:UsersUSERFolder1";
string destinationDirectory = @"C:UsersUSERFolder2";
string[] Files = Directory.GetFiles(rootDirectory);
foreach (string file in Files) {
File.Move(file, $"{destinationDirectory}{Path.GetFileName(file)}");
}
c# move files from one folder to another
/// <summary>
/// Move files and Directory
/// </summary>
/// <param name="fromPath"></param>
/// <param name="toPath"></param>
/// <param name="addDateTimeSubFolder"></param>
Using System.IO;
public static void Move(string fromPath, string toPath, bool addDateTimeSubFolder)
{
if (string.IsNullOrEmpty(fromPath))
{
throw new ArgumentException($"'{nameof(fromPath)}' cannot be null or empty", nameof(fromPath));
}
if (string.IsNullOrEmpty(toPath))
{
throw new ArgumentException($"'{nameof(toPath)}' cannot be null or empty", nameof(toPath));
}
if (addDateTimeSubFolder)
{
var subFolder = DateTime.Now.ToString("YYYYMMDD");
Directory.Move(fromPath, toPath + @"" + subFolder);
}
else
{
Directory.Move(fromPath, toPath);
}
}