批处理文件问题:“1 此时是意外的”

批处理文件问题:“1 此时是意外的”

我对此很陌生,不确定如何修复代码。

我输入:

>for /1 %f in  (1,1,10) do (copy "cover og" "File_copy_%f.xlsx"
/1 was unexpected at this time.

>for %f in (1,1,10) do (copy "cover og" "File_copy_%f.xlsx"
More? copy "cover og"
More? Copy file "cover og"

我尝试关注 YouTube 并在网上查找。
我尝试取出,/1但收到了问题"More?"

有人能解释一下代码出了什么问题以及为什么"More?"会问这个问题吗?

答案1

“1 此时是意外的”

您应该使用 `for /L (字母 L 而不是数字 1):

for /L %f in  (1,1,10) do (copy "cover og" "File_copy_%f.xlsx"

FOR /L

有条件地对一系列数字执行命令。

句法
FOR /L %%parameter IN (start,step,end) DO command

来源:For - 循环遍历数字范围 - Windows CMD - SS64.com


进一步阅读

答案2

Your code has 2 syntax errors:

    /1 not a valid command complement 
    
                  opened (here and ...      didn't close here)
                                                             
for /1 %f in  (1,1,10) do (copy "cover og" "File_copy_%f.xlsx"

1.你看,/1没有参考解释命令语法,没有任何 for 循环的有效选项/补充,可能的用途for /Loop是:

  • 大写为了更好的可视化!

/L      FOR /L %%parameter IN (start,step,end) DO command 

/F      FOR /F ["options"] %%parameter IN (filenameset) DO command 
        FOR /F ["options"] %%parameter IN ("Text string to process") DO command

/R      FOR /R [[drive:]path] %%parameter IN (set) DO command/R

/D      FOR /D [/r] %%parameter IN (folder_set) DO command

/D /R   The option /D /R is undocumented, but can be a useful combination,   
        while it will recurse through all subfolders the wildcard will 
        only match against Folder/Directory names (not filenames).
> for /1 %f in (1,1,10) do (copy "cover og" "File_copy_%f.xlsx"
/1 was unexpected at this time.

2.你打开了一个块(command)但没有关闭它,所以命令解释器正在询问你More?More?直到你用“ ”关闭),他才会停止询问并执行你的命令......

            you opened "(" here    and      didn't close here ")"
                        ⇅                                      ⇅
> for %f in (1,1,10) do (copy "cover og"  "File_copy_%f.xlsx" More?

More? copy "cover og"
More? Copy file "cover og"

在我看来,您的代码最适合您:

for /L %L in (1,1,10) do copy "cover og" "File_copy_%~L.xlsx"

相关内容