How to create folders having same name as files.

Argus

Adept
I have around 150 files.

Is there some way I can automatically create a folder for each of the file and move the file to that folder.
The folder name will be obtained from the filename minus its extension.


example :
For file Filename1.avi a folder Filename1 should be created automatically and the file should be moved to that folder.

Can someone create a script file that can do this job.

Thanks in advance.
 
I do not know scripting but it is easy. In case you do not get a script; let me know. I'll write a windows app for you.

- - - Updated - - -

should be a lot easy in script though (perl or something similar)
 
%
echo off
for %%I in (*.*) do (
mkdir %%~nI
move /y %%I %%~nI
)

1. Copy the above text in a file and name it as somefilename.bat.
2. Then copy the file in the directory where your files exist and run it (double click).
3. .......
4. Profit.


you can edit/play with it if you want using google.


explanation

turns off echoing of commands on the dos prompt.

for %%I in (*.*) do (
FOR command for looping through *.* list of files. also sets the %%I variable to each filename for every iteration.

mkdir %%~nI
Make a directory with the filename excluding the extension

move /y %%I %%~nI
Move the file %%I to the recently created directory without prompting. If there is a file of the same name then it will be overwritten.




If you want to make a copy of the file then instead of "move /y %%I %%~nI" use "copy %%I %%~nI".
 
1. Copy the above text in a file and name it as somefilename.bat.
2. Then copy the file in the directory where your files exist and run it (double click).
3. .......
4. Profit.

Brilliant ! Just the thing I wanted. Thanks :)

also, is there any option in a batch file to rename files such that the decimal and underscores are converted to space.

Tested it on command line, it works well only when there is no space in filename. OK figured it out. I have to wrap the parameters in quotes and it will work for filenames with spaces.
 
Brilliant ! Just the thing I wanted. Thanks :)

also, is there any option in a batch file to rename files such that the decimal and underscores are converted to space.

Tested it on command line, it works well only when there is no space in filename. OK figured it out. I have to wrap the parameters in quotes and it will work for filenames with spaces.

For all sorts of file renaming, I use the free program Renamer. Quite powerful with support for regular expressions.

ReNamer Freeware download and reviews from SnapFiles
 
Back
Top