将文件替换为多个文件夹/子目录 [英] Replacing a file into multiple folders/subdirectories

查看:213
本文介绍了将文件替换为多个文件夹/子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

命令提示符中是否有办法将一个文件复制到另一个文件夹中,并根据其名称将其作为子目录?

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?

我有一个名为5.jpg的图像,该图像已放在目录中每个文件夹中的子文件夹中. 我想在文件夹(包含旧图像)及其子文件夹中进行搜索,然后将所有结果替换为新图像.

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.

推荐答案

我不确定我是否完全了解您.以下代码将在C:\ MyPath \的子文件夹中搜索5.jpg的所有出现,并将其替换为C:\ NewImage \ 5.jpg.我确实对其进行了测试,所以它应该可以工作.

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.

带有参数/R的FOR将在这里为您提供帮助:

FOR with parameter /R will help you here:

FOR /R C:\MyPath\ %%I IN (5.jpg) DO COPY /Y C:\NewImage\5.jpg %%~fI

如果您想了解有关FOR /R的用途和%%~fI含义的更多信息,请查看FOR /? | more,它对此处使用的新Windows cmd可能性提供了很好的解释.

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.

这篇关于将文件替换为多个文件夹/子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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