0
votes

I have a parent folder called "myfiles" which contains several children folders. Each of those children has its own file1.txt

What I need to do is make a copy of file1.txt and rename each to file2.txt in each respective child folder (I need to do this from a command prompt in windows).

The goal is to have every child folder contain a file1.txt and a file2.txt

I've nearly got it with this:

for /r %G in (file1.txt) DO copy %G file2.txt

This command will loop through (when run from the myfiles parent location) and look for any instance of file1.txt and make a copy renamed to file2.txt

But the problem with this is, that instead of file2.txt being created inside each respective child directory, it is being created inside the parent directory (and consequently asking me to overwrite itself each time).

I know I'm close, but any help would be great.

1

1 Answers

0
votes

This would be a quick and dirty way:

for /r %%a in (file1.txt) do (
    copy "%%a" "%%a.TMP"
    ren "%%a.TMP" "file2.txt"
)

The snippet above will create a copy into the correct directory with .TMP appended and then rename the copy to file2.txt.