0

for few days i am trying to write a batch script which can copy a single specific file to all folder and sub-folder in every available drive (C:, D:, E: etc....) in computer.

I am using tree command to revile the list of folder and sub-folder on target drive. then I used for loop + tree command to achieve my goal.

here what i try to do

set a="tree"
for %%g in (' %a% ' ) do (
  echo %%g
)

for now i just print the output of tree command using for loop.

Stephan
  • 53,940
  • 10
  • 58
  • 91
  • 3
    Only `for /f` loops can process commands. – SomethingDark Sep 26 '16 at 07:47
  • Possible duplicate of [Set output of a command as a variable (with pipes)](http://stackoverflow.com/questions/14952295/set-output-of-a-command-as-a-variable-with-pipes) – aschipfl Sep 26 '16 at 08:08
  • Why you don't just use `for ... %%g in ('tree') do (` instead? Do you want the most convoluted code instead of a simple one? – Aacini Sep 27 '16 at 03:22

1 Answers1

0

You might want to use the /R switch for that. Changing to one directory and then using for /r will result in a for-loop that goes through all subdirectories as well.

To get a list of all directories on a device, you can use wmic logicaldisk get deviceid

geisterfurz007
  • 5,292
  • 5
  • 33
  • 54