I am a designer. I need to move files that are all present in one folder to folders that are of the file names. The files are of two formats, .psd and .jpg. I need a batch file that will read the file name, make a folder of part of that file name and move all files that start with that file name into that folder regardless the extension.
For example, if I have 12 files named as
20.psd
20.jpg
20_low.jpg
20_mob.jpg
220.psd
220.jpg
220_low.jpg
220_mob.jpg
120.psd
120.jpg
120_low.jpg
120_mob.jpg
I need a batch file that will make folders 20, 220 and 120 and move all the respective files into the respective folders. So, files 20.psd, 20.jpg, 20_low.jpg and 20_mob.jpg will be in folder named 20 and so on. I tried various links on stackoverflow.com but i couldnt find anything that works. Please help. This is a very monotonous and time consuming job and having a simple program to do my job is useful! :-p
For this i tried these programs with the basic language that i have about dos programming and using examples from stack overflow.
http://stackoverflow.com/questions/1144 ... move-files
http://stackoverflow.com/questions/1999 ... hat-folder
Now the problem i am facing with this code is that this isnt the kind of file name i am using. Also, there is no division as such in the file name. What can i do to make this work?
Batch file to make folders with part of file name
Moderator: DosItHelp
-
- Posts: 1
- Joined: 15 Nov 2015 01:06
Re: Batch file to make folders with part of file name
That may work
Regards
aGerman
Code: Select all
@echo off &setlocal
for /f "delims=" %%i in ('dir /a-d /b *.jpg *.psd') do (
for /f "delims=._" %%j in ("%%i") do (
2>nul md "%%j"
move "%%i" "%%j\"
)
)
Regards
aGerman
Re: Batch file to make folders with part of file name
doshisahil95 wrote:Now the problem i am facing with this code is that this isnt the kind of file name i am using.
Having accurate samples of the filenames will help.