define a pattern to use with dir and get the file names containing numbers

28 ビュー (過去 30 日間)
Boby S
Boby S 2022 年 2 月 24 日
編集済み: Jan 2022 年 2 月 24 日
Hi
I need to 'dir' a folder containing files that has only numbers in their file name:
165454.txt
216541ffgb.txt
In this case, I want to see only the first file in my 'dir' result.
One way is to dir and then filter them using pattern but I do not want to do it.

採用された回答

Jan
Jan 2022 年 2 月 24 日
編集済み: Jan 2022 年 2 月 24 日
This does not work with the patterns of the operating system.
Use a regexp call to filter the names instead:
List = dir('*.txt'):
Name = {List.Name};
% Name = {'1234.txt', '1234s.txt', '1265', 'a1234.txt'};
matchC = regexp(Name, '^\d+\.txt', 'start') % Or: '^[0-9]+\.txt'
match = ~cellfun('isempty', matchC)
List = List(match);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by