0

I'm looking for an equivalent command line on Windows to the following Unix command:

find test -name '*.txt' -print

This command lists every filename which is in the 'test' folder and subfolders, with the .txt extension. In addition, the list displays the subfolder name in the case the file is in a subfolder:

file1.txt
sub/file2.txt
sub/file3.txt
sub2/file4.txt
file5.txt

Does anyone know an equivalent on Windows?

3 Answers 3

0

The good old "dir" command can achieve that. Try dir *.txt /s . dir works with wildcard characters where * - substitution for 0 or more character(s) ? - for exactly 1 character /s - to travel recursively into subfolders

2
  • OK you're right, thanks for your reply. The correct syntax for my case is: dir *.txt /B /S. /B to have only the filenames and /S to display subfolder's files. The problem nom is that I have the full path of my files instead of the relative path. Do you know how to get the relative path?
    – superrache
    Sep 16, 2014 at 12:08
  • You might need a script to remove the current directory from the printed path and display this output ( which is equivalent to relative path) .You can find these scripts online or over at stackoverflow.com/questions/8385454/… Sep 16, 2014 at 12:15
0

or if you're using a modern version of windows that comes with powershell, you can do:

  get-childitem *.txt -recurse|Foreach-Object -Process { Resolve-Path -Relative $_.FullName}

which will get you something like

.\subdir\test.txt
.\subdir2\test1.txt

etc

0

You may also consider using Cygwin which brings you Unix shell and lots of packages to Windows.

You must log in to answer this question.

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