繁体   English   中英

“)此时是意外的”,在变量中创建文件列表-批处理

[英]“) was unexpected at this time”, Create list of files in a variable - Batch

因此,我尝试创建一个批处理文件,该文件将获取deletesrc所有文件,并查找其名称是否与deletedest中的任何文件夹匹配。 为此,我尝试在deletesrc生成一个文件名列表,该列表存储在deletefiles (格式为"first" "second" "third file" )。 然后,我通过在每个文件夹打算循环deletedest并检查它的存在deletesrc (使用 )。 到目前为止,我已经设法:

setlocal enabledelayedexpansion

set "deletesrc=F:\Delete Source"
set "deletedest=C:\Users\Spaced Name\Delete\Dest"

set "deletefiles=" ::I think this is useless, but I would prefer it to be here

for /R "%deletesrc%\" %%i in (*) do (
  set "deletefiles=!deletefiles!^"%%i^" "
  ::random comment that is source of error
)

set deletefiles=!deletefiles!:rTrim

echo !deletefiles!

主要的问题是,我此时不断( ) was unexpected at this time

echo test作为循环中的第一件事,不会更改输出,这意味着循环未运行且首先遇到了错误。 echo放在循环之前,确实会产生输出并在循环之后立即产生错误。

如果有任何语法标准或我不应该/不应该做的事情不能回答问题,我想知道。

您的问题是您将::用作FOR循环内的注释。 您无法执行此操作,因为::实际上是标签指示符,并且它正在中断FOR循环。

更改此行:

::random comment that is source of error

对此:

REM random comment that is source of error

更新

如foxidrive在注释中所述,您可以将::用作FOR内的注释,只要它不是结束( )之前的最后一行即可。

尝试这个:

 set deletefiles=!deletefiles! "%%i"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM