问题
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"
)
回答1:
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"
)
回答2:
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.
来源:https://stackoverflow.com/questions/21128185/run-cmd-command-work-but-run-from-batch-file-doesnt