运行cmd命令,但无法从批处理文件运行 [英] Run cmd command work but run from batch file doesn't

查看:597
本文介绍了运行cmd命令,但无法从批处理文件运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用for循环创建脚本以将文件移动到子文件夹。
开始时,我使用 CMD ,然后将命令复制到 .bat 文件并运行。
结果什么也没有发生。
为什么在 CMD 上执行相同的命令但不能从文件运行?

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 ?

这是我的命令。

@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"
)

这篇关于运行cmd命令,但无法从批处理文件运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆