I have thousands of image files in a folder and I want a program to automatically create new folders and put fifty files in each folder.
Any idea?
Software Recommendations Stack Exchange is a question and answer site for people seeking specific software recommendations. It only takes a minute to sign up.
Sign up to join this communityThis sounds like a PowerShell job. Something like this should work:
# Create 100 folders
1..100 | % {New-Item -Name $_ -ItemType directory}
# select 50 files and move them into folder 1, 2, 3 etc until we hit 100
1..100 | % {
$files = ls | select -First 50
Move-Item $files .\$_
}
If you can compile C# code, I suggest using this program which takes a path (try .
) and a number (50
) as argument. It will create numeric subfolders and move files there. I release this code without warranty and co-licensed as CC-0.
using System;
using System.IO;
namespace MoveNFilesToFolder
{
static class Program
{
static void Main(string[] args)
{
try
{
var path = args[0];
int n = int.Parse(args[1]);
var files = Directory.GetFiles(path, "*.*");
int fileno = 0;
foreach (var file in files)
{
var subdir = Directory.CreateDirectory(Path.Combine(path, "" + (fileno++/n)));
var targetfile = Path.Combine(subdir.FullName, Path.GetFileName(file));
try
{
File.Move(file, targetfile);
}
catch (Exception)
{
Console.WriteLine("Could not move " + file + " to " + targetfile);
}
}
}
catch (Exception)
{
Console.WriteLine("MoveNFilesToFolder <path> <count>");
}
}
}
}