Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 515039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:35:13+00:00 2026-05-13T07:35:13+00:00

Requirement: I need to copy a folder/directory and its contents located in a Machine

  • 0

Requirement:

I need to copy a folder/directory and its contents located in a Machine A to Machine B successfully.

Before starting to copy the following points needs to be consider for my requirement.

  1. If the destination machine,Destination folder is having access permissions or not for the user which he needs to copy from the source folder or directory.

  2. Destination directory should NOT be in hidden or shared and it should be empty if it is already exists.

  3. The destination machine expects the credentials for access,to Handle the same accordingly

How to acheive this?

I’m unable to acheive with the below code:

using System;
using System.IO;

class DirectoryCopyExample
{
 static void Main()
 {
    DirectoryCopy(".", @".\temp", true);
 }

private static void DirectoryCopy(
    string sourceDirName, string destDirName, bool copySubDirs)
{
  DirectoryInfo dir = new DirectoryInfo(sourceDirName);
  DirectoryInfo[] dirs = dir.GetDirectories();

  // If the source directory does not exist, throw an exception.
    if (!dir.Exists)
    {
        throw new DirectoryNotFoundException(
            "Source directory does not exist or could not be found: "
            + sourceDirName);
    }

    // If the destination directory does not exist, create it.
    if (!Directory.Exists(destDirName))
    {
        Directory.CreateDirectory(destDirName);
    }


    // Get the file contents of the directory to copy.
    FileInfo[] files = dir.GetFiles();

    foreach (FileInfo file in files)
    {
        // Create the path to the new copy of the file.
        string temppath = Path.Combine(destDirName, file.Name);

        // Copy the file.
        file.CopyTo(temppath, false);
    }

    // If copySubDirs is true, copy the subdirectories.
    if (copySubDirs)
    {

        foreach (DirectoryInfo subdir in dirs)
        {
            // Create the subdirectory.
            string temppath = Path.Combine(destDirName, subdir.Name);

            // Copy the subdirectories.
            DirectoryCopy(subdir.FullName, temppath, copySubDirs);
        }
    }
 }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:35:14+00:00Added an answer on May 13, 2026 at 7:35 am

    For file sending you can see your OWN question here:
    Machine to Machine File transfer
    AND some short script here:
    http://www.eggheadcafe.com/community/aspnet/2/10076226/file-transfer-from-one-ma.aspx

    Than, using FileInfo and DirectoryInfo – get the attributes:
    http://msdn.microsoft.com/en-us/library/system.io.directoryinfo%28VS.71%29.aspx

    Connecting to the remote folder can be done using DirectorySecurity:
    http://msdn.microsoft.com/en-us/library/system.security.accesscontrol.directorysecurity.aspx

    Enjoy!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project requirement where I need to authenticate against ActiveDirectory in a
I have been given a requirement where I need to support multiple databases in
Hey all, I have something of an interesting requirement for my project. I need
I need assistance finding a delivery method that best fulfills the following requirements: We
I need to batch create images with text. Requirements: arbitrary size of bitmap PNG
My requirements: Support .NET Compact Framework 2.0 and Windows Mobile 6.0 devices. Only need
I need to build a simple, single user database application for Windows. Main requirements
A requirement for an ASP.Net 2.0 project I'm working on limits a certain field
My requirement is I have server J2EE web application and client J2EE web application.
My requirement is just to display a set of values retrieved from database on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.