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

  • SEARCH
  • Home
  • 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 8855665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:11:14+00:00 2026-06-14T14:11:14+00:00

I can do this so simply with files, like so: public static void MoveAllFilesFromDesktopToJDrive()

  • 0

I can do this so simply with files, like so:

public static void MoveAllFilesFromDesktopToJDrive()
        {
            DirectoryInfo di = new DirectoryInfo(@"C:\Users\Tafe\Desktop\");
            DirectoryInfo Jdrive = new DirectoryInfo(@"J:\");

            foreach (FileInfo fi in di.GetFiles())
            {
                if (Path.GetFileName(fi.FullName) != "desktop.ini")
                {                      
                    fi.MoveTo(Jdrive.FullName + Path.GetFileName(fi.FullName));
                }    
            }
        }

But trying the same operation on directories tells me I can’t move directories accross volumes. OK then, so this is what I’ve tried:

 public static void MoveAllDirsFromDeskTopToJDrive()
        {
            DirectoryInfo di = new DirectoryInfo(@"C:\Users\Tafe\Desktop\");
            DirectoryInfo Jdrive = new DirectoryInfo(@"J:\");

            foreach (DirectoryInfo dirs in di.GetDirectories())
            {
               Directory.CreateDirectory(Jdrive + Path.GetFileName(dirs.FullName)); 

            }
        }

This copies the names of the files, but not the contents, I would just move the contents like I did with my MoveAllFilesFromDesktopToJDrive() method, but the directories contain subdirectories and subdirectories and such, so I can’t figure it out. I know a TINY bit about recursion, but not enough to even attempt this. Also, It can’t be that hard can it? There has to be something better in the API to facilitate this? If not, any help to complete this method MoveAllFilesFromDesktopToJDrive() would be a lifesaver!

  • 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-06-14T14:11:15+00:00Added an answer on June 14, 2026 at 2:11 pm

    Try looping this somewhere within your code:

        string fileName = "test.txt";
        string sourcePath = @"C:\Users\Public\TestFolder";
        string targetPath =  @"C:\Users\Public\TestFolder\SubDir";
    
        // Use Path class to manipulate file and directory paths. 
        string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
        string destFile = System.IO.Path.Combine(targetPath, fileName);
    
        // To copy a folder's contents to a new location: 
        // Create a new target folder, if necessary. 
        if (!System.IO.Directory.Exists(targetPath))
        {
            System.IO.Directory.CreateDirectory(targetPath);
        }
    
        System.IO.File.Copy(sourceFile, destFile, true);
    

    For more details visit this link : http://msdn.microsoft.com/en-us/library/cc148994.aspx

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

Sidebar

Related Questions

I'm going to try and explain this as simply as I can, it's most
I've tried many functions already, but I simply can't figure this out. The right
This seems to be something obvious but I simply can't find info by googling.
Can someone tell me how to accomplish this mapping using Fluent NHibernate? It's simply
I have this slideshow that I'm trying to simply move up, but I can't
I can't seem to get back on track with this one. I simply put
Can anybody help me with this simple code?? #include <iostream> using namespace std; void
I know this sounds like a broad question but I can narrow it down
Can someone explain this simple, yet deceiving, anomaly? There are two models, where B
Can't seem to achieve this simple functionality! All I want is to clear a

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.