1

i want to make a batch file, This Batch file must look out, into a folder with the name "Draft" and for every sub-folder will be make a search for a .txt file "list.txt" and when finds this .txt file, Then will be execute a copy from the folder "Draft" to the folder "Ready". I have written a small script but i have some issues.

@echo off
:loop

  for /d %%i in ('dir "C:\Users\ntosis\Desktop\Draft" /ad /o:d /s /b') do ( 
  SET a=%%i
  echo %a%
  )

echo Folder is empty or does not exist
timeout /t 15
goto loop

The problem in this small part of the script is that, the variable "a" cannot save the name of the folder, if i change the echo %a% to echo Hello World then the script prints only one time the message and not as long as the loop runs. Any ideas?

4

1 Answer 1

0

You can probably do this in a one liner:

for /R "C:\Users\ntosis\Desktop\Draft" %G in (list.txt) do ( type "%G" >> "C:\Users\ntosis\Desktop\Ready\list.txt"

This will concatenate all your list.txt files into a single list.txt in the Ready folder.

Make sure your Ready folder is not a subfolder of your Draft folder otherwise you'll get duplicated lines.

If you want to run from a batch file dont forget to double your %:

for /R "C:\Users\ntosis\Desktop\Draft" %%G in (list.txt) do ( type "%%G" >> "C:\Users\ntosis\Desktop\Ready\list.txt"

If you want to copy the whole source directory structure with your list.txt files then thats a bit different.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .