Page 1 of 1

bat file dont run

Posted: 24 Apr 2021 04:39
by Sperhak
Hi sorry my english.
I have some .mkv film in D:\cdd i write script to sort him to folder.

Code: Select all

for %i in (*mkv) do md "%~ni"
for %i in (*mkv) do move "%i" "%~ni"
This is code in bat file. Bat file is in D:\cdd
Bat file not working.

When i run win+r type cmd to cmd type
D:
cd cdd
for %i in (*mkv) do md "%~ni"
for %i in (*mkv) do move "%i" "%~ni"

Code working

Can you help me what i doing bad in batfile?

Re: bat file dont run

Posted: 24 Apr 2021 13:33
by ShadowThief
In a batch script, your for loop variable needs to use two %s instead of one.

Code: Select all

for %%i in (*mkv) do md "%%~ni"
for %%i in (*mkv) do move "%%i" "%%~ni"

Re: bat file dont run

Posted: 24 Apr 2021 14:06
by Sperhak
Many thanks, work.

Re: bat file dont run

Posted: 25 Apr 2021 21:10
by Squashman
Sperhak wrote:
24 Apr 2021 14:06
Many thanks, work.
Please consider reading the help file for a command before asking questions. The help file literally explains the single and double percent usage on the 8th line.