Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate folder structure with x number of files per folder
    primarykey
    data
    text
    <p>I've got a number of folders with over 500,000 items in each. I want to break these down into folders of 10,000 (or 50,000 or 5,000 or whatever the user defines.) </p> <p>There's obviously something wrong in my logic, because as it currently stands it just moves all my files into the first folder it creates. I've tried playing around with different combinations of foreach and where, but no luck. </p> <pre><code> //Find all the files to move string[] files = Directory.GetFiles(textBox1.Text, "*.*", SearchOption.TopDirectoryOnly); //Use selects the number of files to go in each folder long h = long.Parse(tbFilePerFolder.Text); //Used later long i = 0; //Used later long j = 0; //Get the number of folders to create long k = files.Count() / h; //Report back the number of files found lblFilesFound.Text = "Files Found: " + files.Count(); //Create the necessary number of folders, plus 1 to pick up remainders while (j &lt;= k + 1) { Directory.CreateDirectory(textBox1.Text + @"\" + j.ToString("00000")); lblFoldersCreated.Text = "Folders Created: " + j; j++; } //Get each folder that's just been created string[] folders = Directory.GetDirectories(textBox1.Text, "*.*", SearchOption.TopDirectoryOnly); //For each of those folders... foreach (string folder in folders) { //While there is less than the requested number of folders... while (i &lt;= h) { //Get a list of the currently existing files string[] files2 = Directory.GetFiles(textBox1.Text, "*.*", SearchOption.TopDirectoryOnly); //And iterate through it, moving to the defined directory foreach (string file in files2) { File.Move(file, folder + @"\" + Path.GetFileName(file)); lblFilesMoved.Text = "Files Moved: " + i; i++; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload