Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

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

        }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #move #files #folder
ADD COMMENT
Topic
Name
2+2 =