Replacing a file into multiple folders/subdirectories

前端 未结 3 566
遥遥无期
遥遥无期 2020-12-31 05:30

Is there a way in command prompt to take one file and copy it into another folder and its subdirectories based on its name?

I have an image named 5.jpg that has been

相关标签:
3条回答
  • 2020-12-31 05:50

    Probably there is one more (simpler) way.

    Use the replace command:

    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.

    0 讨论(0)
  • 2020-12-31 05:58

    To do this work with several files, both paths are needed enclosed in quotes:

    replace "C:\*.Txt" "C:\Some_Root_Folder_Which_Contains_Multiple_SubFolders" /s
    

    The asterisk to make changes on all files with the ".txt" prefix.

    0 讨论(0)
  • 2020-12-31 06:08

    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.

    0 讨论(0)
提交回复
热议问题