tags:

views:

30

answers:

1

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.

+1  A: 

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.

FOR with parameter /R will help you here:

FOR /R C:\MyPath\ %%I IN (5.jpg) DO COPY /Y C:\NewImage\5.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.

schnaader
Now that I look at it more closely, it looks like it works exactly how you say.I need it to only add it into the subfolders that have the file in it because there are some that don't have the file.
abney317
seems to work if I put an asterisk in the parentheses like (*5.jpg)Thanks
abney317