Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to split a huge folder?
    primarykey
    data
    text
    <p>We have a folder on Windows that's ... huge. I ran "dir > list.txt". The command lost response after 1.5 hours. The output file is about 200 MB. It shows there're at least 2.8 million files. I know the situation is stupid but let's focus the problem itself. If I have such a folder, how can I split it to some "manageable" sub-folders? Surprisingly all the solutions I have come up with all involve getting all the files in the folder at some point, which is a no-no in my case. Any suggestions?</p> <p>Thank Keith Hill and Mehrdad. I accepted Keith's answer because that's exactly what I wanted to do but I couldn't quite get PS working quickly.</p> <p>With Mehrdad's tip, I wrote this little program. It took 7+ hours to move 2.8 million files. So the initial dir command did finish. But somehow it didn't return to console.</p> <pre><code>namespace SplitHugeFolder { class Program { static void Main(string[] args) { var destination = args[1]; if (!Directory.Exists(destination)) Directory.CreateDirectory(destination); var di = new DirectoryInfo(args[0]); var batchCount = int.Parse(args[2]); int currentBatch = 0; string targetFolder = GetNewSubfolder(destination); foreach (var fileInfo in di.EnumerateFiles()) { if (currentBatch == batchCount) { Console.WriteLine("New Batch..."); currentBatch = 0; targetFolder = GetNewSubfolder(destination); } var source = fileInfo.FullName; var target = Path.Combine(targetFolder, fileInfo.Name); File.Move(source, target); currentBatch++; } } private static string GetNewSubfolder(string parent) { string newFolder; do { newFolder = Path.Combine(parent, Path.GetRandomFileName()); } while (Directory.Exists(newFolder)); Directory.CreateDirectory(newFolder); return newFolder; } } } </code></pre>
    singulars
    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.
 

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