Q: I need help with a batch file. I'm the Keeper of Records for my AA Meeting. We record the meeting. The old sound guy put everything in folders and then gave them to me. The new guy uses a Mac and doesn't use folders, so I have dozens of files that are supposed to be in folders. He uses the format "ken buckner 07-05-08.aif" for the files.
Is there a way for a batch file to read a filename, create a folder with that name, then move the file into the folder, and do it until it runs out of files? It would save me a couple of hours, if you can figure it out. - Ken B.
A: Batch file? Who needs a batch file? We'll do the whole job with a single command line! The Command Prompt in Windows XP and Vista has hidden powers, you see. First let's look at the command itself:
FOR %v IN ("ken*.aif") DO MD TEMP&MOVE "%v" TEMP&REN TEMP "%v"
The FOR command takes every file matching the file specification "ken*.aif" and runs the command line following DO, swapping each filename for the variable %v. You can string multiple commands together on a single line by separating them with an ampersand (&) - handy! For each file, then, we create a folder named TEMP, move the file into that folder, and then rename the folder to the file's original name. This two-step process is needed because you can't have a file and an identically-named folder in the same location.
Now, you said you want the folder to have the same name ...