0

I need to list out the names of the files based on given type. Is there any tool to do that or is there any source code so that i can get the list of the files with given extension.

Example: If ".txt" is given then the output must contain list of all the text files in a specific directory.

2
  • Belongs on superuser.com
    – Paul R
    Jun 17, 2010 at 11:10
  • 1
    Is this a programming question? If so, please say what language.
    – Don Roby
    Jun 17, 2010 at 11:11

2 Answers 2

1

You can use find, e.g.

% DIR=/foo/bar/blech
% SUFFIX=txt
% find "${DIR}" -name \*.${SUFFIX}

If you don't want to find matching files in subdirectories then change this last line to:

% find "${DIR}" -depth 1 -name \*.${SUFFIX}

If you are using Windows then you will need to install cygwin or similar before you can use find.

4
  • Thanks for you reply.I need this filtering to be done in windows.Is there any way to do so
    – AJJ
    Jun 17, 2010 at 10:59
  • If you need an OS-spcific solution then you should really tag your question accordingly - I've done this for you now. Also, your question probably belongs on superuser.com. I've added a note to the answer for Windows users.
    – Paul R
    Jun 17, 2010 at 11:09
  • thanks.I am new to stackoverflow.so they may be mistakes in tagging questions.The problem is that i need to filter files from .iso image.Is there any tool that will do that or if it can be done in java?
    – AJJ
    Jun 18, 2010 at 3:28
  • @user369218: See my edit above - you can just install cygwin and use my original suggestion - no programming required.
    – Paul R
    Jun 18, 2010 at 10:00
0

If you just want the file names:

dir /b *.txt

If you want all the files in subdirectories:

dir /b/s *.txt

If you want to know more about "dir":

dir /?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.