开发者

How can i filter the files based on type?

开发者 https://www.devze.com 2023-01-03 23:59 出处:网络
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.

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开发者_C百科 contain list of all the text files in a specific directory.


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.


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 /?
0

精彩评论

暂无评论...
验证码 换一张
取 消