Click here to Skip to main content
Click here to Skip to main content

Organize Folder by Mover

, 3 Apr 2009
Rate this:
Please Sign up or sign in to vote.
The program divides the folders into a wanted folder or path according to a number that the user will enter.
Mover_Setup

Introduction

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 !

Background

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)
{
    MessageBox.Show(
         "You can not enter a number that is larger than the number" +
         "of folders in source folder !",
         "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    return;
}

// 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;
    this.Refresh();

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

    //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; 
        else
        {
            // 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);
            Directory.CreateDirectory(newFolder);
            // copying contents
            CopyFolder(foldrs[index], newFolder);
            index = index + 1;
        }
    }

}
//at the end we delete the source folder
DeleteFolder(input);
irectory.Delete(input);

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.

License

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

About the Author

ibramoha

Palestinian Territory (Occupied) Palestinian Territory (Occupied)
No Biography provided

Comments and Discussions

 
GeneralMy vote of 1 PinmemberdvptUml17-Oct-09 15:05 
GeneralMy vote of 2 PinmemberBigTuna3-Apr-09 6:57 
GeneralI find this extremely useless.... PinmemberSeishin#3-Apr-09 6:51 
GeneralRe: I find this extremely useless.... PinmemberMember 38638313-Apr-09 8:51 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140718.1 | Last Updated 3 Apr 2009
Article Copyright 2009 by ibramoha
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid