Page 1 of 1
Help with a batch
Posted: 25 Oct 2012 12:07
by ArieS
Hello,
I need some help with a batch script. I don't know anything about it and I found this batch on the net.
@echo off
for %%a in (*.*) do (
md "%%~na" 2>nul
move "%%a" "%%~na"
)
I need to move 4 files in 1 folder.
I’m using it for XBMC and it moves 3 out of the 4 to 1 folder (i.e nameofmovie.mkv, nameofmovie.tbn, nameofmovie.nfo) except nameofmovie-fanart.jpg
This one is moved to its own folder.
Anyone can help with the missing command?
Thanks in advance!
Re: Help with a batch
Posted: 25 Oct 2012 15:54
by trebor68
Here not tested code.
This code will work when a file "nameofmovie.mkv" exist.
Code: Select all
@echo off
for %%a in (*.mkv) do (
md "%%~na" 2>nul
move "%%~na*.*" "%%~na"
)
This code will not work perfect when you have files like this:
NameOfMovie.mkvNameOfMovie2.mkv
Re: Help with a batch
Posted: 25 Oct 2012 20:12
by foxidrive
This should move all files to a single folder. It chooses one file to get the name from for the folder, and uses that name for all of the files.
Code: Select all
@echo off
for %%a in (*.*) do set "name=%%~na" & goto :gotit
:gotit
md "%name%" 2>nul
for %%a in (*.*) do move "%%a" "%name%"
EDITED: The do keyword was added
Re: Help with a batch
Posted: 25 Oct 2012 23:59
by ArieS
trebor68 wrote:Here not tested code.
This code will work when a file "nameofmovie.mkv" exist.
Code: Select all
@echo off
for %%a in (*.mkv) do (
md "%%~na" 2>nul
move "%%~na*.*" "%%~na"
)
This code will not work perfect when you have files like this:
NameOfMovie.mkvNameOfMovie2.mkv
Thank you
so much !!
It worked perfectly!
I guess I'll be careful if I have some movies with sequels that everything is moved to the right folder.
You rock dude!
Re: Help with a batch
Posted: 26 Oct 2012 00:00
by ArieS
foxidrive wrote:This should move all files to a single folder. It chooses one file to get the name from for the folder, and uses that name for all of the files.
Code: Select all
@echo off
for %%a in (*.*) do set "name=%%~na" & goto :gotit
:gotit
md "%name%" 2>nul
for %%a in (*.*) move "%%a" "%name%"
This one created a new folder nameofmovie-fanart but didn't move anything to it.
Thanks for your time though.
Re: Help with a batch
Posted: 26 Oct 2012 00:30
by foxidrive
That was a typo on my part, I forgot the DO keyword. This is tested.
Code: Select all
@echo off
for %%a in (*.*) do set "name=%%~na" & goto :gotit
:gotit
md "%name%" 2>nul
for %%a in (*.*) do move "%%a" "%name%"
Re: Help with a batch
Posted: 26 Oct 2012 00:37
by foxidrive
ArieS wrote:trebor68 wrote:Code: Select all
@echo off
for %%a in (*.mkv) do (
md "%%~na" 2>nul
move "%%~na*.*" "%%~na"
)
Thank you
so much !!
It worked perfectly!
I guess I'll be careful if I have some movies with sequels that everything is moved to the right folder.
You rock dude!
trebor68's solution is fine unless the sorted filename has 'movie name.!artwork.bmp' first in the list, when it will skip the rest. When using FAT32 this will be an issue.
Re: Help with a batch
Posted: 26 Oct 2012 10:56
by ArieS
foxidrive wrote:That was a typo on my part, I forgot the DO keyword. This is tested.
Code: Select all
@echo off
for %%a in (*.*) do set "name=%%~na" & goto :gotit
:gotit
md "%name%" 2>nul
for %%a in (*.*) do move "%%a" "%name%"
This one moves everything to 1 folder, even different file names.
Re: Help with a batch
Posted: 26 Oct 2012 20:12
by foxidrive
Yes, it does. Your first example used *.* too and you said it worked, but only moved 3 out of 4 files.
Obviously that leads us to assume that there were only 4 files in the folder.
Maybe you can rephrase what you need to do.