[英]Windows move command not moving the matching file to destination folder using bat
I created a windows bat file which will create a directory and then create subdirectories finally it need to move the matching file to the destination folder but it is not moving showing error "A duplicate file name exists, or the file cannot be found" but I have the matching string in the folder. 我创建了一个Windows bat文件,该文件将创建一个目录,然后创建子目录,最终它需要将匹配的文件移动到目标文件夹,但它没有移动,并显示错误“存在重复的文件名,或者找不到该文件”,但是我在文件夹中有匹配的字符串。 Please help on this
请帮忙
my batch script shows below 我的批处理脚本如下所示
set AUTOMATEDDIR=C:/test/2122/Inter/Test/WEB
CD %AUTOMATEDDIR%\..\Reports\Deliverable
FOR %%d IN (AgentCreate) DO (
MKDIR "%%d"
FOR %%e IN (Requests Responses) DO (
echo inside
MKDIR "%%d\%%e"
MOVE "Unidentified\%%e\*%%d*" "%%d\%%e"
)
)
when I execute the above script it shows below error 当我执行上面的脚本时,它显示下面的错误
C:\test\2122\Inter\Test\Reports\Deliverable>(
MKDIR "AgentCreate"
FOR %e IN (Requests Responses) DO (
echo inside
MKDIR "AgentCreate\%e"
MOVE "Unidentified\%e\*AgentCreate*" "AgentCreate\%e"
)
)
C:\test\2122\Inter\Test\Reports\Deliverable>(
echo inside
MKDIR "AgentCreate\Requests"
MOVE "Unidentified\Requests\*AgentCreate*" "AgentCreate\Requests"
)
inside
A duplicate file name exists, or the file
cannot be found.
C:\test\2122\Inter\Test\Reports\Deliverable>(
echo inside
MKDIR "AgentCreate\Responses"
MOVE "Unidentified\Responses\*AgentCreate*" "AgentCreate\Responses"
)
inside
A duplicate file name exists, or the file
cannot be found.
My folder Requests contains folder "Res_20121203_Test_1" as below 我的文件夹请求包含文件夹“ Res_20121203_Test_1”,如下所示
C:\test\2122\Inter\Test\Reports\Deliverable\Unidentified\Requests\Res_20121203_Test_1
Res_20121203_Test_1 folder contains files like below
-20121203B001601-292XtOHAAgentCreate601
-20121203B002603-292XtOHAAgentCreate603
The above files matching "AgentCreate" need to move "AgentCreate\\Requests" folder also matching files to "AgentCreate\\Responses" 上面匹配“ AgentCreate”的文件需要将“ AgentCreate \\ Requests”文件夹也移动到“ AgentCreate \\ Responses”文件夹
Please help on this why it is not moving. 请对此提供帮助,为什么它不会移动。
FOR %%d IN (AgentCreate) DO (
MKDIR "%%d" 2>nul
FOR %%e IN (Requests Responses) DO (
echo inside
MKDIR "%%d\%%e" 2>nul
FOR /f "delims=" %%t IN ('dir /s /b /a-d "Unidentified\%%e\*%%d*" 2^>nul') do MOVE "%%t" "%%d\%%e" >nul
)
)
I misread the requirement. 我误读了要求。 This worked for me.
这对我有用。
The 2>nul
suppresses error messages. 2>nul
禁止显示错误消息。 >nul
suppresses "moved" reports and 2^>nul
suppresses 'file not found' output of the dir
. >nul
禁止“移动”报告, 2^>nul
禁止dir
“找不到文件”输出。 The caret is necessary to tell cmd
that the redirection is part of the command to be executed, not part of the for
. 插入符号必须告诉
cmd
重定向是要执行的命令的一部分,而不是for
一部分。
Essetially, scan the trget directory for matching files /s
in subdirectories /b
in basic form (filename only) /ad
and no directorynames. 通常,以基本形式(仅文件名)
/ad
扫描trget目录中的子目录/b
中的文件/s
,以匹配文件/s
且没有目录名。
You may want to try echo move
to verify operation. 您可能想尝试
echo move
来验证操作。
Please note that \\ is a directory-separator and / is a switch in winbatch. 请注意\\是目录分隔符, /是winbatch中的开关。 Some commands accept / as directory separators, but not all.
有些命令接受/作为目录分隔符,但不是全部。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.