0

Expanding upon this example: Copying a file to multiple folders in the same directory

I want to copy all file .txt from C:\Newfolder\ to folder C:\Output\*\rack\*\cloth

example for destination folder:

C:\Output\name1\rack\nick1\cloth
C:\Output\name2\rack\nick2\cloth
.
.
C:\Output\name100\rack\nick100\cloth

so I have tried this:

FOR /D %%1 IN (C:\Output\*) DO (
    IF EXIST "%%1\rack" (
        COPY /Y C:\Newfolder\*.txt "%%1\rack\*\cloth"
    )
)

the problem all txt file doesn't copied to destination folder

Community
  • 1
  • 1
tukimin
  • 3
  • 1
  • Do not use decimal digits for `for` variables, use letters (e. g., `%%I`)! Anyway, why are you using a `for /D` loop for resolving the first wild-card but for the second? Let me recommend to put quotation marks around all paths, and to use `%%~I` rather than `%%I`... – aschipfl Mar 22 '17 at 11:35

1 Answers1

0

If you use the same FOR /D method for each unknown subfolder name then you should get to where you want to be:

@ECHO OFF
FOR /D %%A IN ("C:\Output\*") DO IF EXIST "%%A\rack\" FOR /D %%B IN ("%%A\rack\*"
) DO IF EXIST "%%B\cloth\" COPY /Y "C:\Newfolder\*.txt" "%%B\cloth"
Compo
  • 36,585
  • 5
  • 27
  • 39