フィルターのクリア

How do i print file names that exist in certain folder in matlab table with out file extension?

7 ビュー (過去 30 日間)
Dear all..
i'm using the following code to write file names that exist in folder or sub-folder ... in matlab table.. but its write these files along with thier extension .. such that if file AA is text file.. then its name in table is AA.txt and so on.. how do i avoid extension in my code.. thanks
projectdir = 'D:\test';
d = dir(fullfile(projectdir, '*'));
files = [];
for subdir = d([d.isdir] & ~ismember({d.name},{'.', '..'}))'
subfiles = dir(fullfile(projectdir, subdir.name, '*.txt'));
[subfiles.folder] = deal(subdir.name);
files = [files; subfiles];
end
details = struct2table(files);
  2 件のコメント
KSSV
KSSV 2017 年 6 月 9 日
First place does this code work? I don't think so..you have initialed
dir = D:\test;
YOu have used inbuilt function dir as a variable, this will throw error in second line itself...
ahmed obaid
ahmed obaid 2017 年 6 月 9 日
Dear KSSV; test is a folder include large number of sub-folders... every sub-folder involve some text files.. i'm able to write their names but perhaps without extension ...
here i'm writing html pages ... but perhaps i can written their names with out extension

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

採用された回答

Stephen23
Stephen23 2017 年 6 月 9 日
編集済み: Stephen23 2017 年 6 月 9 日
Use fileparts to get the filename without the extensions. Something like this, where C is a cell array of those filenames:
[P,N,E] = cellfun(@fileparts,C,'uni',0)
  5 件のコメント
Stephen23
Stephen23 2017 年 6 月 9 日
編集済み: Stephen23 2017 年 6 月 9 日
Running this (note that I changed the directory for my test):
projectdir = '.';%'D:\test';
D = dir(fullfile(projectdir, '*'));
files = [];
for subdir = D([D.isdir] & ~ismember({D.name},{'.', '..'}))'
subfiles = dir(fullfile(projectdir, subdir.name, '*.txt'));
[subfiles.folder] = deal(subdir.name);
files = [files; subfiles];
end
[~,N] = cellfun(@fileparts,{files.name},'uni',0);
[files.name_no_ext] = deal(N{:});
gives this output:
>> files.name_no_ext
ans = test1
ans = test2
ans = file3

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by