Copy a file into every folder and its subfolders

15,188

Use following script:

@echo off
    for /r "%CD%" %%f in (.) do (
      copy "Text.txt" "%%~ff" > nul
    )

Credit: https://stackoverflow.com/a/1321539/1756941

Edit:

@echo off
    Setlocal EnableDelayedExpansion
    cls
    set currentDirectory=%CD%
    FOR /D %%g IN ("*") DO (
        Pushd %CD%\%%g
        FOR /D %%f IN ("*") DO (
            copy "%currentDirectory%\Text.txt" "%%~ff"
        )
    Popd
    )
pause
Share:
15,188
John Smith
Author by

John Smith

I am an autodidact. I love webdesign and programming. I have many projects in my head and if I need help, I ask in forums or here on stackoverflow. Without you guys (and grrrls, of course), I would be lost. Thanks to everyone who helped me!

Updated on June 04, 2022

Comments

  • John Smith
    John Smith almost 2 years
    "Here I am"-folder
      |
      |--- mainfolder 1
      |          |
      |          |--- subfolder 1
      |          |--- subfolder 2
      |
      |--- mainfolder 2
      |          |
      |          |--- subfolder 1
      |          |--- subfolder 2
    

    I want to place a batch-file into the "Here I am"-folder and execute it from there. It should copy a file named text.txt into all mainfolders and into their subfolders.