繁体   English   中英

将所有 usr 文件从子文件夹复制到单独文件夹的批处理脚本

[英]batch script to copy all usr files from sub folders to separate folders

我正在尝试创建一个批处理脚本,它将目录内的子文件夹中的所有 usr 文件复制到 2 个单独的文件夹中,然后从其原始位置删除文件。 到目前为止,我已经完成了:

for /R S:\Customer Services\EDI\NET EDI %%f in (*.usr) do copy T:\edidata\netedi\Outboxtest

for /R S:\Customer Services\EDI\NET EDI %%f in (*.usr) do copy T:\edidata\netedi\Outbox backup

然而,这不是复制文件,也没有发生任何事情,我在哪里出错了? 我还需要添加什么才能从原始文件夹中删除文件?

编辑:

从我阅读答案的方式来看,我认为它应该变成:

for /R "S:\Customer Services\EDI\NET EDI" %%f in (*.usr) do copy %%F "T:\edidata\netedi\Outboxtest"

for /R "S:\Customer Services\EDI\NET EDI" %%f in (*.usr) do copy %%F "T:\edidata\netedi\Outbox backup"

但这仍然不起作用。 我猜我只是没有正确理解在说什么

编辑2:

我在脚本末尾添加了 PAUSE 命令,以查看它运行时发生的情况,这就是出现的情况:

S:\Customer Services\EDI\NET EDI>for /R "S:\Customer Services\EDI\NET EDI" %f in (*.usr) do copy %F "T:\edidata\netedi\Outboxtest"

S:\Customer Services\EDI\NET EDI>copy %F "T:\edidata\netedi\Outboxtest"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy %F "T:\edidata\netedi\Outboxtest"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy %F "T:\edidata\netedi\Outboxtest"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy %F "T:\edidata\netedi\Outboxtest"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy %F "T:\edidata\netedi\Outboxtest"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy %F "T:\edidata\netedi\Outboxtest"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy %F "T:\edidata\netedi\Outboxtest"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>for /R "S:\Customer Services\EDI\NET EDI" %f in (*.usr) do copy %F "T:\edidata\netedi\Outbox backup"

S:\Customer Services\EDI\NET EDI>copy %F "T:\edidata\netedi\Outbox backup"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy %F "T:\edidata\netedi\Outbox backup"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy %F "T:\edidata\netedi\Outbox backup"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy %F "T:\edidata\netedi\Outbox backup"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy %F "T:\edidata\netedi\Outbox backup"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy %F "T:\edidata\netedi\Outbox backup"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy %F "T:\edidata\netedi\Outbox backup"
The system cannot find the file specified.

希望最后一次编辑。

现在我有

for /R "S:\Customer Services\EDI\NET EDI" %%G in (*.usr) do copy %%G "T:\edidata\NetEDI\Outboxtest"

for /R "S:\Customer Services\EDI\NET EDI" %%G in (*.usr) do copy %%G "T:\edidata\NetEdi\Outbox backup"

PAUSE

但它仍然无法正常工作,给出的 output 是:

S:\Customer Services\EDI\NET EDI>for /R "S:\Customer Services\EDI\NET EDI" %G in (*.usr) do copy %G "T:\edidata\NetEDI\Outboxtest"

S:\Customer Services\EDI\NET EDI>copy S:\Customer Services\EDI\NET EDI\gentest.usr "T:\edidata\NetEDI\Outboxtest"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy S:\Customer Services\EDI\NET EDI\Asda\asdatest.usr "T:\edidata\NetEDI\Outboxtest"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy S:\Customer Services\EDI\NET EDI\Costcutter\CCINV24052020.usr "T:\edidata\NetEDI\Outboxtest"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy S:\Customer Services\EDI\NET EDI\Costcutter\cctest.usr "T:\edidata\NetEDI\Outboxtest"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy S:\Customer Services\EDI\NET EDI\McColls Local Account\mccollstest.usr "T:\edidata\NetEDI\Outboxtest"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy S:\Customer Services\EDI\NET EDI\Scotmid\scotmidtest.usr "T:\edidata\NetEDI\Outboxtest"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy S:\Customer Services\EDI\NET EDI\Tesco\tescotest.usr "T:\edidata\NetEDI\Outboxtest"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>for /R "S:\Customer Services\EDI\NET EDI" %G in (*.usr) do copy %G "T:\edidata\NetEdi\Outbox backup"

S:\Customer Services\EDI\NET EDI>copy S:\Customer Services\EDI\NET EDI\gentest.usr "T:\edidata\NetEdi\Outbox backup"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy S:\Customer Services\EDI\NET EDI\Asda\asdatest.usr "T:\edidata\NetEdi\Outbox backup"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy S:\Customer Services\EDI\NET EDI\Costcutter\CCINV24052020.usr "T:\edidata\NetEdi\Outbox backup"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy S:\Customer Services\EDI\NET EDI\Costcutter\cctest.usr "T:\edidata\NetEdi\Outbox backup"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy S:\Customer Services\EDI\NET EDI\McColls Local Account\mccollstest.usr "T:\edidata\NetEdi\Outbox backup"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy S:\Customer Services\EDI\NET EDI\Scotmid\scotmidtest.usr "T:\edidata\NetEdi\Outbox backup"
The system cannot find the file specified.

S:\Customer Services\EDI\NET EDI>copy S:\Customer Services\EDI\NET EDI\Tesco\tescotest.usr "T:\edidata\NetEdi\Outbox backup"
The system cannot find the file specified.

所以我收集的是它现在正在获取文件,但是找不到将它们复制到的文件夹? 文件目标对他们来说都是正确的,我已经仔细检查过,所以不确定还有什么问题。

您的命令中至少存在三个问题。

  1. 您只为copy命令提供了一个参数。 它需要sourcedestination 您可能忘记使用for提供的%%F参数。

     for /R <path> %%f in (*.usr) do copy %%FT:\edidata\netedi\Outboxtest
  2. 另一个问题是你的路径包含空格而你不是 escaping 它们。 你应该用双引号括起你的路径:

     "S:\Customer Services\EDI\NET EDI"

    同样的问题很可能适用于T:\edidata\netedi\Outbox backup 当前命令

    for /RS:\Customer Services\EDI\NET EDI %%f in (*.usr) do copy T:\edidata\netedi\Outbox backup

    将从T:\edidata\netedi\Outbox复制到.\backup

    您也必须为参数使用引号,因为在您的情况下它会扩展为包含空格的路径!

     ... do copy "%%f" T:\edidata\netedi\Outboxtest

    通常最好使用下划线 ( _ ) 或连字符 ( - ) 而不是路径中的空格,这样您就不需要在每个命令中转义空格。

  3. %%f参数区分大小写,不能作为%%F引用。

我相信你应该这样做:

... copy %%f T:\edidata\netedi\Outboxtest\ (or ...Outbox\test\)

... T:\edidata\netedi\Outbox 备份的故事是什么? 那不应该是:

... copy %%f T:\edidata\netedi\Outbox\backup\

暂无
暂无

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

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