how to get files name without format extension inside a folder

i have a folder with many files with different extension.i need .txt format files name alone to be saved in a variable in matlab?

回答 (1 件)

ES
ES 2014 年 1 月 16 日

0 投票

allTextFiles=dir('*.txt');;
number_of_files=length(allTextFiles);
Name_ofFile_1=allTextFiles(1).name;...

3 件のコメント

ES
ES 2014 年 1 月 16 日
編集済み: ES 2014 年 1 月 16 日
If you do not want name extension (i.e., .txt) you can truncate the "Name_ofFile"
For eg: Name_ofFile=Name_ofFile(1:end-4);%length('.txt') = 4
sandy
sandy 2014 年 1 月 16 日
thanks CW...below code showing only last file name .that too with file extension..any help to store the names for every loop with only file name,not with extension
path = 'C:\Users\test\';
listing = dir(fullfile(path, '*.txt'));
nof=length(listing);
for i=1:numel(listing)
nameoffile=listing(i).name;
end
ES
ES 2014 年 1 月 16 日
The variable you have used "nameoffile" can hold only one string. So when the for loop finishes, it will have the last filename only.. Use a cell instead.
path = 'C:\Users\test\';
listing = dir(fullfile(path, '*.txt'));
nof=length(listing);
for i=1:numel(listing)
nameoffile{i}=listing(i).name;
end

サインインしてコメントする。

カテゴリ

質問済み:

2014 年 1 月 16 日

コメント済み:

ES
2014 年 1 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by