I try to create script with for loop to move file to sub folder. At the beginning, I work with CMD
then I copy command to .bat
file and run it. The result is nothing happens. Why the same command on CMD
works but run from file not ?
Here is my command.
@echo off
setlocal enableDelayedExpansion
SET FOL=J:\test
SET ENDNUM=2
for /l %x in (1, 1, %ENDNUM%) do (
md "%FOL%/0%x/subfolder"
move /Y "%FOL%\0%x\*" "%FOL%\0%x\subfolder"
)
You have to double-up the percentage signs on for
commands in a batch file.
for /l %%x in (1, 1, %ENDNUM%) do (
md "%FOL%/0%%x/subfolder"
move /Y "%FOL%\0%%x\*" "%FOL%\0%%x\subfolder"
)
Check encoding of your .bat file. When I used UTF-8, command prompt displayed error:
C:\Users\***\Desktop>´╗┐cmd
'´╗┐cmd' is not recognized as an internal or external command,
operable program or batch file.
When I used ANSI encoding, the .bat file worked as expected.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.