windows 将文件替换为多个文件夹/子目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3312310/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Replacing a file into multiple folders/subdirectories
提问by abney317
Is there a way in command prompt to take one file and copy it into another folder and it's subdirectories based on it's name?
有没有办法在命令提示符下获取一个文件并将其复制到另一个文件夹中,并根据它的名称将其作为子目录?
I have an image named 5.jpg that has been put in a sub-folder that is in every folder in a directory. I want to do a search inside of the folder (with the old image) and its sub-folders and replace all of the results with the new image.
我有一个名为 5.jpg 的图像,该图像已放在目录中每个文件夹中的子文件夹中。我想在文件夹(使用旧图像)及其子文件夹内进行搜索,并用新图像替换所有结果。
采纳答案by schnaader
I'm not sure if I understood you completely. The following code will search for all occurences of 5.jpg in subfolders of C:\MyPath\ and replaces them with C:\NewImage\5.jpg. I did test it, so it should work.
我不确定我是否完全理解你。以下代码将在 C:\MyPath\ 的子文件夹中搜索所有出现的 5.jpg,并将它们替换为 C:\NewImage\5.jpg。我确实测试过它,所以它应该可以工作。
FOR with parameter /R will help you here:
带有参数 /R 的 FOR 将在这里帮助您:
FOR /R C:\MyPath\ %%I IN (5.jpg) DO COPY /Y C:\NewImage.jpg %%~fI
If you want more information about what FOR /R
does and what %%~fI
means, have a look at FOR /? | more
which gives nice explanations about the new Windows cmd possibilities that are used here.
如果你想了解更多关于什么是什么FOR /R
和什么%%~fI
意思的信息,看看FOR /? | more
它对这里使用的新 Windows cmd 可能性给出了很好的解释。
回答by Baljeetsingh
Probably there is one more (simpler) way.
可能还有一种(更简单)的方法。
Use the replace
command:
使用replace
命令:
replace C:\SourceFile.Txt C:\Some_Root_Folder_Which_Contains_Multiple_SubFolders /s
As the command itself says it just replaces the file, which already existed in sub-directories.
正如命令本身所说,它只是替换已经存在于子目录中的文件。