Arjun Bhardwaj
Arjun Bhardwaj

Reputation: 11

How to make a batch file copy itself in all folders and subfolders

I want to make a batch file copy itself in all folders and subfolders. For example : i have a folder on my desktop called "root". inside that folder i have 3 folders : 'a','b' and 'c'. Inside 'a' there are yet other folders a1, and a2.

Now i want to make a batch file to copy itself in every folder available.

I tried using for loop like this:

for /d %%a in (*.*) do copy file.txt "%%a"

but it doesn't copy to all folders

Please help thnx

Upvotes: 1

Views: 655

Answers (2)

Rafael
Rafael

Reputation: 3122

for /R %%a in (%~nx0) do copy /y "%~nx0" "%%a"

Upvotes: 1

npocmaka
npocmaka

Reputation: 57272

for /d /r %%# in (*) do copy /y "%~f0" "%%#"

Upvotes: 1

Related Questions