program to automatically make folders..?

Soldato
Joined
7 Jul 2004
Posts
8,125
Location
Gloucester
I have about 200 files in a folder, I need each file in a separate folder of its own, with the folder named the same as the file... Is there a program that can save me time :confused:
 
Copy the following to a file say called first.bat

mkdir dump
for %%a in (*.*) do second.bat %%a

Copy the following into a file called second.bat

mkdir dump\%1
move %1 dump\%1

Basically you'll end up with 2 batch files, the first creates a folder called dump which is where all the folders and files will end up, it then scans the current folder and the calls the second batch file with the name of each file in turn, the second batch file then makes a folder using the name of the file and then moves the file into that folder.

As both these batch file sit in the same folder and the batch files fairly stoopid they'll be moved into the dump folder too. I'd suggest you try it on a test set of files rather then the target and modify the file(s) as required.
 
If you have python installed put this script in the dir you want to do then run python filename.py (You may want to test it works on windows ok first on a different directory in case it hoses your filesystem :p )

Code:
import os
import shutil

dirs = os.listdir(".")
for file in dirs:
  if os.path.isfile(file):
    newpath = os.mkdir(file + "new")
    shutil.move(file,file+"new")
    os.rename(file+"new",file)

Edit: Infact just use that batch script above, will do what you want and not depend on python.
 
Last edited:
Back
Top Bottom