Search
 
SCRIPT & CODE EXAMPLE
 

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);
Comment

c# move files from one directory to another

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)}");
}
Comment

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);
            }

        }
Comment

PREVIOUS NEXT
Code Example
Csharp :: unity instantiate prefab rotation 
Csharp :: selection sort in c# 
Csharp :: how to remove space between string in c# 
Csharp :: c-sharp - get current page url/path/host 
Csharp :: c# use hashtable check if key exists 
Csharp :: C# calculate sum of digits of a number 
Csharp :: arrays in c# 
Csharp :: how to see image from website in wpf 
Csharp :: check shell command success 
Csharp :: add all elements in a list c# 
Csharp :: 2d rotation unity 
Csharp :: c# access session in class 
Csharp :: how return only value of array in laravel 
Csharp :: string list to object array in c# 
Csharp :: color unity 
Csharp :: c# int to string 
Csharp :: c# get folder path from file path 
Csharp :: c# razor add disabled to button if 
Csharp :: c# list object sort alphabetically 
Csharp :: remove items from one list in another c# 
Csharp :: c# add object to array 
Csharp :: single line and multiline comments in c 
Csharp :: creating a streamwiter file C# 
Csharp :: how to know character is a digit or not in c# 
Csharp :: unity gui text 
Csharp :: minimize window windows forms application c# 
Csharp :: use raycast unity new input system 
Csharp :: Dyanmically create datatable in c# 
Csharp :: wpf get function name 
Csharp :: asp.net response.redirect new tab 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =