bat file dont run

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Sperhak
Posts: 2
Joined: 24 Apr 2021 04:24

bat file dont run

#1 Post by Sperhak » 24 Apr 2021 04:39

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?

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: bat file dont run

#2 Post by ShadowThief » 24 Apr 2021 13:33

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"

Sperhak
Posts: 2
Joined: 24 Apr 2021 04:24

Re: bat file dont run

#3 Post by Sperhak » 24 Apr 2021 14:06

Many thanks, work.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: bat file dont run

#4 Post by Squashman » 25 Apr 2021 21:10

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.

Post Reply