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 7509587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:57:40+00:00 2026-05-29T22:57:40+00:00

I have an if statement that checks if a directory exists and if it

  • 0

I have an if statement that checks if a directory exists and if it does it copies that folder to the specified location.

The entire copy process is on an array of pre-determined folder locations, for loop goes through the array and copies the folder and its data at each location.

At the moment there are 200 different locations to copy with more still to be added.

I am trying to implement a progress bar around the copying of these 200+ folders but keep running in to errors, I think the issue I am having is mainly due to the array, the tutorials I’ve seen (which differed greatly from one another) covered just basic file copying.

Any help or tips on how to get a progress bar working would be much appreciated 🙂

for (int i = 0; i < pathArray.Length; i++)
{

   string sourcePath = pathArray[i];

   //MISSING CODE

   if (System.IO.Directory.Exists(sourcePath))
   {                   

      System.IO.Directory.CreateDirectory(targetPathProper);

      foreach (string dirPath in System.IO.Directory.GetDirectories(sourcePath,"*",
          (System.IO.SearchOption.AllDirectories)))
      {
         System.IO.Directory.CreateDirectory(dirPath.Replace(sourcePath, 
                targetPathProper));
      }

      foreach (string newPath in System.IO.Directory.GetFiles(sourcePath, "*", 
          (System.IO.SearchOption.AllDirectories)))
      {
         System.IO.File.Copy(newPath, newPath.Replace(sourcePath, 
             targetPathProper), true);
      }

   } //end if
} // end for
  • 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-29T22:57:42+00:00Added an answer on May 29, 2026 at 10:57 pm

    You say you get an error, what error are you getting?

    As for your progress bar, you can simply increment at each base directory in the array. No real need to increment for every file. Or if there is a need to indicate progress on every file you can have two progress bars.

    progressBar1.Maximum = pathArray.Length;
    progressBar1.Value = 0;
    for (int i = 0; i < pathArray.Length; i++)
    {
    
       string sourcePath = pathArray[i];
    
       progressBar1.Value++;
    
       if (System.IO.Directory.Exists(sourcePath))
       {                   
    
          System.IO.Directory.CreateDirectory(targetPathProper);
          string[] subDirs = System.IO.Directory.GetDirectories(sourcePath,"*",(System.IO.SearchOption.AllDirectories))
          progressBar2.Maximum = subDirs.Length;
          progressBar2.Value = 0;
          foreach (string dirPath in subDirs)
          {
             progressBar2.Value++;
             System.IO.Directory.CreateDirectory(dirPath.Replace(sourcePath, 
                targetPathProper));
             Application.DoEvents();
          }
    
          progressBar2.Value = 0;
          foreach (string newPath in subDirs)
          {
             progressBar2.Value++;
             System.IO.File.Copy(newPath, newPath.Replace(sourcePath, 
                 targetPathProper), true);
             Application.DoEvents();
          }
    
       } //end if
    } // end for
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a statement that checks if a tab is selected: $( '#social_edit_pannels' ).tabs({
I have some code that iterates through files in a directory and does useful
I have LINQ statement that looks like this: return ( from c in customers
In an Oracle 10g environment, I have a statement that needs to be executed
I have a SQL statement that looks like: SELECT [Phone] FROM [Table] WHERE (
I have a delete statement that's going against one of my core application tables.
I have an UPDATE statement that's intended to update a status field for a
I have a sql statement that uses Difference => http://msdn.microsoft.com/en-us/library/ms188753.aspx I do this in
I have an IF statement that consists of two separate function calls passing values
I have a LINQ statement that returns an anonymous type. I need to get

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.