将文件从父目录复制到许多子目录中的特定文件夹的 DOS 命令
我正在尝试自学一些简单的 DOS 命令,并使用相对简单的命令来复制或移动文件,但是这个特定的请求对我来说是一个挑战,并且希望能从这个论坛获得一些专业知识。
C:\Parent\library.eds (location of my source file)
每当我更新父目录中的library.eds时,我都想将该文件复制到包含名为“LIB”的文件夹的每个子目录中。我已将子目录标准化为以下内容:
C:\Parent\Child1\INPUT
C:\Parent\Child1\OUTPUT
C:\Parent\Child1\LIB {paste library.eds here}
C:\Parent\Child2\INPUT
C:\Parent\Child2\OUTPUT
C:\Parent\Child2\LIB {paste library.eds here}
并循环直到所有具有 LIB 目录的子目录都包含更新的文件“library.eds”
谢谢您的帮助! 标记
I'm trying to teach myself some simple DOS commands and have used relatively simple commands to copy or move files, however this specific request is presenting a challenge for me and would appreciate some expertise from this forum.
C:\Parent\library.eds (location of my source file)
Any time I update library.eds in the parent directory, I would like to copy that file into every Child directory that contains a folder named "LIB". I have standardized the Child directories to the following:
C:\Parent\Child1\INPUT
C:\Parent\Child1\OUTPUT
C:\Parent\Child1\LIB {paste library.eds here}
C:\Parent\Child2\INPUT
C:\Parent\Child2\OUTPUT
C:\Parent\Child2\LIB {paste library.eds here}
and loop through until all children with LIB directories contain the updated file "library.eds"
Thank you for your help!
Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下面是一个可以帮助您入门的命令:
一旦您让它按照您想要的方式工作,请删除
@ECHO
部分以实际执行复制:这些命令的额外帮助
这是如何工作的
这可以让您执行 < code>command,并循环其输出。每行都将被填充到
%variable
中,并且可以在otherCommand
中展开任意多次,无论您喜欢在哪里。%variable
在实际使用中只能是单字母名称,例如%V
。这使您可以忽略
'command'
输出的任何空格,因此它可以正确处理名称中包含空格的目录。这将搜索
C:\Parent
下名为LIB
的所有文件。由于/s
,它将递归地遍历子目录。它只会查找目录(因为/a:D
)。由于/b
,它将以对循环有用的方式输出它们。这在批处理文件中是必需的。如果您在命令提示符下执行此操作,则可以使用 %P 代替。
Here's a command that can get you started:
Once you get it working the way you want, remove the
@ECHO
part to actually do the copy:Extra help for these commands
How this works
This lets you execute
command
, and loop over its output. Each line will be stuffed into%variable
, and can be expanded out inotherCommand
as many times as you like, wherever you like.%variable
in actual use can only have a single-letter name, e.g.%V
.This lets you ignore any whitespace output by
'command'
, so it properly handles directories that have spaces in their names.This will search for all files under
C:\Parent
that have the nameLIB
. It will recursively go through subdirectories because of/s
. It will only find directories (because of/a:D
). It will output them in a way that is useful for looping, because of/b
.This is required in batch files. If you did this on the command prompt, you would use %P instead.
如果您事先知道所有子目录,最简单的解决方案是批处理文件 批处理文件教程
我不知道循环在 ms dos 中如何工作,但在 linux bash shell 中循环编程很简单。
无论如何,批处理文件是最简单的选择
if you know all the child directories before hand the simplest solution is batch files tutorial on batch files
I dont know how loops work in ms dos but in linux bash shell loops are simple to program..
Any ways batch files are the simplest option
如果您可以下载 cygwin,那么您可以使用以下 bash 脚本来完成这项工作,而无需对其进行硬编码
代码
PS 您将需要将文件夹名称从 tmp 更改为 LIB,将文件名从 LOL 更改为 ur 文件名。该脚本非常不言自明。
Unix shell 比 MS-DOS 更好,所以无论如何获取 cygwin 可能是个好主意
if you can download cygwin then you can use the following bash script to do the job without hardcoding it
The code
P.S you will need to change the name of the folder from tmp to LIB and the filename from LOL to ur file name .. The script is pretty self explanatory.
Unix shells are better than MS-DOS so it might be a good idea to get cygwin anyways