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 批处理文件:如果我知道文件夹名称的开头,但不知道整个名称,如何进入文件夹_Batch File - Fatal编程技术网

Batch file 批处理文件:如果我知道文件夹名称的开头,但不知道整个名称,如何进入文件夹

Batch file 批处理文件:如果我知道文件夹名称的开头,但不知道整个名称,如何进入文件夹,batch-file,Batch File,我试图创建一个批处理文件,用于从一个位置复制到另一个位置,大约50个文件夹 假设文件夹的名称如下所示: 文件夹1:1abc Folder2:2qer 文件夹3:3asd Folder4:4jfd ... 等等我知道文件夹名称以一个数字开头,所以我会这样做 :COPYDIAG //The counter part in the XCOPY is what I don't get XCOPY %counter%"\Documents\*.* OtherLocation\ SET /A countDi

我试图创建一个批处理文件,用于从一个位置复制到另一个位置,大约50个文件夹

假设文件夹的名称如下所示: 文件夹1:1abc Folder2:2qer 文件夹3:3asd Folder4:4jfd ... 等等我知道文件夹名称以一个数字开头,所以我会这样做

:COPYDIAG
//The counter part in the XCOPY is what I don't get
XCOPY %counter%"\Documents\*.* OtherLocation\
SET /A countDiag1 += 1
IF %countDiag1%==%endDiag1% (GOTO :EOF) ELSE (GOTO :COPYDIAG)

那么,如果我知道文件夹名称以递增数字开头,那么如何获取整个文件夹名称的字符串呢?

您可以使用带有通配符的CD来选择部分目录名称
CD 1*
将移动到以
1
开头找到的第一个文件夹。然后做你自己的事情,然后把它放回一个文件夹级别。请记住,您现在位于不同的文件夹中,因此可能需要在
XCopy
语句中对此进行补偿

@Echo Off
Set Counter=0
Set EndCounter=3
:NextFolder
Set /A Counter=%Counter%+1
CD %Counter%*
XCopy Documents\*.* ..\OtherLocation\
CD ..
If Not %Counter%==%EndCounter% Goto :NextFolder

您可以使用带有通配符的CD来选择部分目录名
CD 1*
将移动到以
1
开头找到的第一个文件夹。然后做你自己的事情,然后把它放回一个文件夹级别。请记住,您现在位于不同的文件夹中,因此可能需要在
XCopy
语句中对此进行补偿

@Echo Off
Set Counter=0
Set EndCounter=3
:NextFolder
Set /A Counter=%Counter%+1
CD %Counter%*
XCopy Documents\*.* ..\OtherLocation\
CD ..
If Not %Counter%==%EndCounter% Goto :NextFolder

作为一个小贴士,当我试图到达一条复杂的路径时,我经常使用通配符。我使用
CD\Users\Username\Documents\visualstudio 2010\Projects\Company.Product.Feature\bin\Release
而不是
CD\Users\U*\Doc*\*2010\Pro*\*Feature\bin\Rel*
。显然,你必须熟悉你的文件夹,以确保没有混淆。
D*
Desktop还是Documents?作为一个小提示,我经常在尝试进入复杂路径时使用通配符。我使用
CD\Users\Username\Documents\visualstudio 2010\Projects\Company.Product.Feature\bin\Release
而不是
CD\Users\U*\Doc*\*2010\Pro*\*Feature\bin\Rel*
。显然,你必须熟悉你的文件夹,以确保没有混淆。是桌面还是文档?