Search code examples
windowsbatch-filecmdwmic

How to list all files and folders present in a hard disk using batch commands?


I am trying to print list of all the files and folders present in different partitions of hard disk using :

for %d in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (ifexist %d: (dir %d:/s >> %Systeminfo_TXT%))

but this doesn't print any output ?

Where am i going wrong !!


Solution

    • Did you define the variable %Systeminfo_TXT%?

    • The "ifexist" command is not valid in batch files. Instead, you can use the "if" command with the "exist" operator to check if a drive exists.

      for %%d in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do ( if exist %%d: ( dir %%d:\ /s >> %Systeminfo_TXT% ) )