Help with a batch
Moderator: DosItHelp
Help with a batch
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!
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
Here not tested code.
This code will work when a file "nameofmovie.mkv" exist.
This code will not work perfect when you have files like this:
NameOfMovie.mkv
NameOfMovie2.mkv
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.mkv
NameOfMovie2.mkv
Re: Help with a batch
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.
EDITED: The do keyword was added
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
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.mkv
NameOfMovie2.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
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
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
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
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
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.
Obviously that leads us to assume that there were only 4 files in the folder.
Maybe you can rephrase what you need to do.