批量For循环 - 去除文件夹名称的文件 [英] Batch For Loop - removing file from folder names

查看:354
本文介绍了批量For循环 - 去除文件夹名称的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含喜欢的东西的文本文件:

I have a text file which contains things like:

C:\\文件夹A \\ Test.txt的

"C:\Folder A\Test.txt"

我需要某些文件和它们各自的集装箱从一个目录复制到一个新的目录,但只有那些文件,指定我和他们的父文件夹的结构。

I need to copy certain files and their respective containers to a new directory from a directory, but only those files I specify and their parent folder structures.

在我的批处理:

for /f "delims=" %%a in (C:\audit\test.txt) do (
  robocopy "%%~dpa" "Z:\" "%%~nxa" /E /COPY:DAT /PURGE /MIR /R:1000000 /W:30
)
pause

然而,失败的Robocopy,可能与尾部的反斜杠做。来源得到混合起来,同时显示了文件夹,并在Z :.这意味着T他从 %%〜文件名NXA 将是新的,而不是复制文件的一部分。有任何想法吗?

However, it fails the robocopy, probably to do with the trailing backslash. The Source gets mixed up and shows both the folder and the Z:. This means t he file name from %%~nxa is then part of the destination rather than the file to copy. Any ideas?

推荐答案

反斜杠被视为在这种情况下,转义字符,因为它马上precedes结束如果你追加一个的路径,其结果将是相同的路径,但反斜线将不再precede结束 ,因此不会被视为为结束引号转义字符。

The backslash is treated as an escape character in this case because it immediately precedes the closing ". If you append a . to the path, the result will be the same path but the backslash will no longer precede the closing " and therefore will not be treated as an escape character for the ending quote.

在这个例子中你已经发布源和目标路径与结束\\ 。因此,你需要添加一个 这两个:

In the example you've posted both the source and target paths end with a \. Therefore you'll need to add a . to both:

for /f "delims=" %%a in (C:\audit\test.txt) do (
  robocopy "%%~dpa." "Z:\." "%%~nxa" /E /COPY:DAT /PURGE /MIR /R:1000000 /W:30
)
pause

这篇关于批量For循环 - 去除文件夹名称的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆