none
copy folder RRS feed

Answers

  • Hello Jordanhal,

    Please try this,recreate a folder and copy all the files from original directory to the new one

    class Program
        {
            static void Main(string[] args)
            {
                DirectoryInfo sourceDir = new DirectoryInfo(@"D:\12_files");
                DirectoryInfo destinationDir = new DirectoryInfo(@"D:\backUp\12_files");
                CopyDirectory(sourceDir, destinationDir);
            }
    
            static void CopyDirectory(DirectoryInfo source, DirectoryInfo destination)
            {
                if (!destination.Exists)
                {
                    destination.Create();
                }
                // Copy all files.
                FileInfo[] files = source.GetFiles();
                foreach (FileInfo file in files)
                {
                    file.CopyTo(Path.Combine(destination.FullName,file.Name));
                }
    
                // Process subdirectories.
                DirectoryInfo[] dirs = source.GetDirectories();
                foreach (DirectoryInfo dir in dirs)
                {
                    // Get destination directory.
                    string destinationDir = Path.Combine(destination.FullName, dir.Name);
    
                    // Call CopyDirectory() recursively.
                    CopyDirectory(dir, new DirectoryInfo(destinationDir));
                }
            }
        }

    Sincerely,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Fei HuModerator Thursday, October 19, 2017 11:05 AM
    • Marked as answer by Jordanhal Wednesday, November 29, 2017 9:35 PM
    Wednesday, October 18, 2017 8:31 AM
    Moderator

All replies

  • I am using C# and i want save a backup.

             jordan

    Tuesday, October 17, 2017 3:13 PM
    • Proposed as answer by Fei HuModerator Wednesday, October 18, 2017 8:31 AM
    Tuesday, October 17, 2017 3:47 PM
  • If you are also interested in showing the familiar Progress Dialog of Operating System, then use the FileSystem class: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/file-system/how-to-provide-a-progress-dialog-box-for-file-operations.

    • Proposed as answer by Fei HuModerator Wednesday, October 18, 2017 8:31 AM
    Tuesday, October 17, 2017 6:10 PM
  • Hello Jordanhal,

    Please try this,recreate a folder and copy all the files from original directory to the new one

    class Program
        {
            static void Main(string[] args)
            {
                DirectoryInfo sourceDir = new DirectoryInfo(@"D:\12_files");
                DirectoryInfo destinationDir = new DirectoryInfo(@"D:\backUp\12_files");
                CopyDirectory(sourceDir, destinationDir);
            }
    
            static void CopyDirectory(DirectoryInfo source, DirectoryInfo destination)
            {
                if (!destination.Exists)
                {
                    destination.Create();
                }
                // Copy all files.
                FileInfo[] files = source.GetFiles();
                foreach (FileInfo file in files)
                {
                    file.CopyTo(Path.Combine(destination.FullName,file.Name));
                }
    
                // Process subdirectories.
                DirectoryInfo[] dirs = source.GetDirectories();
                foreach (DirectoryInfo dir in dirs)
                {
                    // Get destination directory.
                    string destinationDir = Path.Combine(destination.FullName, dir.Name);
    
                    // Call CopyDirectory() recursively.
                    CopyDirectory(dir, new DirectoryInfo(destinationDir));
                }
            }
        }

    Sincerely,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Fei HuModerator Thursday, October 19, 2017 11:05 AM
    • Marked as answer by Jordanhal Wednesday, November 29, 2017 9:35 PM
    Wednesday, October 18, 2017 8:31 AM
    Moderator