1

I would like to be able to search for specific directory with specific name and save their paths into a text file. for example, for a directory titled abc in parition c:\

I would like to search for all of its occurances of ‘abc’ in ‘c:\’ and save the paths of the occurrences into a text file titled paths.txt.

Example:

C:.
├───aaa
│   └───aab
├───abc
│   └───grumble
└───whatever
    └───abc
        ├───abc
        └───pla

I want to get a text file containing:

C:\abc
C:\whatever\abc
C:\whatever\abc\abc
Amrmsmb
  • 1
  • 27
  • 104
  • 226

1 Answers1

1

You would need to combine several things to do this. The dir command is able to search recursively, show things attributed as directorys and use a plain display format - here are the relevant switches (to see more, use dir /?):

DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/S]
or
DIR [/A[[:]attributes]] [/B] [/S] [drive:][path][filename]

  [drive:][path][filename]
          Identifies drive, directory and/or files.
  /A      Lists files with specified attributes.
  Attribute D directories
  /S      Lists files and all subdirectories.
  /B      Simple format (no header, no summary).

You can pipe the result in a file using this syntax: dir /AD /S /B abc > somefile.txt - abc is the directory name - you can also use wildcards like dir /AD /S /B *abc* > somefile.txt to find any directory that contains abc.

Using dir *abc* /AD /S /B > somefile.txt works the same - position of it does not seem to matter.

See

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69