追加名称为 johnsfiles.txt 的所有文件
我想将所有名为 johnsfiles.txt 的文件附加到我的 C 驱动器上。
这就是每个具有此名称的文件,无论子目录如何
我如何实现此目的?
I would like to append all files named johnsfiles.txt on my c drive.
Thats every file with this name regardless of sub directorys
How do i achive this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
@Ryan Bemrose 的解决方案很好,因为它将产生预期的结果(找到的所有 johnsfiles.txt 文件的合并内容)。但是,它也可能会导致出现多个有关丢失文件的错误消息。问题是,FOR /R 循环的行为有所不同,具体取决于您在括号中指定的是掩码还是实际名称。在前一种情况下,它只会迭代找到的文件,而在后一种情况下,它会在分支的所有文件夹中“查找”指定的文件,包括那些实际上不包含该文件的文件夹。似乎名称被完全忽略,命令只是迭代所有子文件夹。
这有点奇怪,除了在循环中使用 DIR /S /B 命令的输出之外,我无法克服它,如下所示:
@Ryan Bemrose's solution is good in that it would produce the expected result (the merged contents of all the
johnsfiles.txt
files found). However it might also result in multiple error messages about missing files. The thing is, theFOR /R
loop behaves differently depending on whether you specify a mask or an actual name in the brackets. In the former case it would only iterate over the files found, while in the latter case it would 'find' the specified file in all the folders in the branch, including those not actually containg the file. Seems like the name is perfectly ignored and the command simply iterates over all the subfolders.That is a bit strange, and I couldn't overcome it otherwise than by using the output of the
DIR /S /B
command in the loop, like this:尝试
try