Click here to Skip to main content
15,565,661 members
Articles / Programming Languages / C#
Posted 3 Apr 2009

Tagged as


5 bookmarked

Organize Folder by Mover

Rate me:
Please Sign up or sign in to vote.
2.00/5 (3 votes)
3 Apr 2009CPOL2 min read
The program divides the folders into a wanted folder or path according to a number that the user will enter.


This article describes my first program in C# that deals with a folder and its files. This program is useful to those that suffer from a large number of folders in their desktops or volumes and want to arrange their folders with specific names and move them from one location to another.

The program divides the folders into a wanted folder or path according to a number that the user will enter. If a user want to move a11 folders from folder A to folder B and wants to put two folders in a new created folder in B, with a new name, this program will do that easily !


The mover program needs some inputs to work properly, which are:

  1. The divide number.
  2. The name of new created folder (Optional).
  3. Source folder or path.
  4. Destination folder or path.

My program counts the number of folders in the source folder, puts the result in x and checks that the divide number is less than x. Dividing x by the entered number and ceiling the result will give us the least number of folders needed to be created, and contain the folders to be transfered from the source.

The program name for the new created folder (which will host the folder to be transfered) with the entered name as inputted by the user. If the user wants to not enter this field, the program will name the folder with the mover word. In both cases, the program will append a number to the name.

Using the Code

// first of all we get the names of all folders in the source folder
string[] foldrs = Directory.GetDirectories(input);

// we ensure that the user will not enter a number larger than the number 
//      of folders in the source folder
if (numberOfFolders > foldrs.Length)
         "You can not enter a number that is larger than the number" +
         "of folders in source folder !",
         "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

// getting the number of folders to be moved, which are in the source folder
double x = foldrs.GetLength(0);

// the value of variable index is used as index to get each folder in the source folder
int index = 0;

// we create folders to accommodate all the folders in the source folder
// Math.Ceiling(x / numberOfFolders ) is the least number of folders that
// can host the comming folders from souce folder

for (int i = 0; i < Math.Ceiling(x / numberOfFolders); i++)
    runStatus.Text = "Running !";
    runStatus.ForeColor = Color.Red;

    // create folders that will contain the copy of folders comming from source
    string folderName = output + "\\" + newFoldersName + " (" + i + ")";

    //copying from source into destination
    for (int j = 0; j < numberOfFolders; j++)
        //the end of source folders, there is no folder of that value of index
        if (index >= foldrs.Length) break; 
            // create the same folder in the destination
            // foldrs[index].ToString().Substring(
            // foldrs[index].ToString().LastIndexOf("\\") + 
            // 1 get the name of each folder in the source folder
            string newFolder = folderName + "\\" + foldrs[index].ToString().Substring(
                foldrs[index].ToString().LastIndexOf("\\") + 1);
            // copying contents
            CopyFolder(foldrs[index], newFolder);
            index = index + 1;

//at the end we delete the source folder

I used two methods that do the action of moving (which is copying, then deleting) which is included in the downloadable code at the top of this article.

Points of Interest

The idea is simple but useful and made me start to develop a program to organize and arrange folders and files by type, quantity and number, and displays information about it.

Forgive me for my poor English. It's my first article, my first program, and want it not to be my last.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Palestinian Territory (Occupied) Palestinian Territory (Occupied)
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

GeneralMy vote of 1 Pin
dvptUml17-Oct-09 16:05
dvptUml17-Oct-09 16:05 
GeneralMy vote of 2 Pin
BigTuna3-Apr-09 7:57
BigTuna3-Apr-09 7:57 
GeneralI find this extremely useless.... Pin
Seishin#3-Apr-09 7:51
Seishin#3-Apr-09 7:51 
GeneralRe: I find this extremely useless.... Pin
Member 38638313-Apr-09 9:51
Member 38638313-Apr-09 9:51 
I can only imagine moving my 750gb movie folder Smile | :)

A desktop indexing solution might be easier to use.

And there is the perfect solution called Search Folders.
Instant organisation where ever it is

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.