Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 使用bat文件在文件路径中插入阵列号_Batch File - Fatal编程技术网

Batch file 使用bat文件在文件路径中插入阵列号

Batch file 使用bat文件在文件路径中插入阵列号,batch-file,Batch File,我手动创建了8个文件夹 我想将目标文件复制到dest,如下所示 target31 => dest31 target32 => dest32 target33 => dest33 target34 => dest34 因此,我写了如下,这是不工作的 31 32 33 34 should be array and end of the filename(target,dest) should be array to match file name @echo

我手动创建了8个文件夹

我想将目标文件复制到dest,如下所示

target31  => dest31
target32  => dest32
target33  => dest33
target34  => dest34

 
因此,我写了如下,这是不工作的

31 32 33 34 should be array and end of the filename(target,dest) should be array to match file name
@echo off
set list = 31 32 33 34
(
    for %%a in (%list%) do (
        xcopy /s C:\Users\xxx\Desktop\check\target%%a C:\Users\xxxx\Desktop\check\dest%%a
        echo %%a
    )
)
我试过了,但没用

31 32 33 34 should be array and end of the filename(target,dest) should be array to match file name
@echo off
set list = 31 32 33 34
(
    for %%a in (%list%) do (
        xcopy /s C:\Users\xxx\Desktop\check\target%%a C:\Users\xxxx\Desktop\check\dest%%a
        echo %%a
    )
)

另一种方法是将数字放在两个括号中
(31 32 33 34)


此外,还应将文件路径放在两个双引号之间

试试我的代码:

@echo off
for %%a in (31 32 33 34) do (
 xcopy "C:\Users\xxx\Desktop\check\target%%a" "C:\Users\xxxx\Desktop\check\dest%%a" /S
)

Raghu Nandan,我已经将上面评论中的信息添加到了您的问题中,通过使用按钮,请您以后自己这样做。你现在也可以删除上面的评论,因为它不再需要了。您还需要修改
set
命令,以使用正确的语法,
set“list=31 32 33 34”
;当前,您有一个名为
%list%
的变量,该变量表示
%list%
=nothing。当然,您可以将
%list%
更改为
%list%
,但我不建议将其作为更改
set
命令的首选项。我还建议您按照标准做法,在提供的示例中没有可见的空格或有毒字符的情况下,将文件路径双引号引到,这仍然是一个好习惯。此外,为了额外的安全性,请提供xcopy的路径及其扩展,这样您就不必依赖经常意外或不知情地修改的变量<代码>“%\uuuuu APPDIR\uuuuuuu%xcopy.exe”“%USERPROFILE%\Desktop\check\target%%a”“%USERPROFILE%\dest%%a\”/S未设置变量
%list%
。它设置变量
%list%
,即名称为
的变量。使用它,它就会工作。