How I can write the names of file in note bad without extension?

4 ビュー (過去 30 日間)
Ameligege
Ameligege 2015 年 3 月 19 日
コメント済み: Ameligege 2015 年 3 月 19 日
Hello
I Want To write The names of file that I read it Using for loop without any comma and extension Here is the code that I tried It but the out put is not what I want Can Any one Help ,Please?
for i = 1 : length(srcFiles)
dlmwrite('target.txt',srcFiles(i).name, '-append', 'newline', 'pc');
Here is the format of this code output
0,0,4,_,L,0,_,0,.,b,m,p
0,0,4,_,L,1,_,0,.,b,m,p
Here is the output that I want
004_L0_0
004_L1_0
I am Waiting for any help............

採用された回答

wil
wil 2015 年 3 月 19 日
編集済み: wil 2015 年 3 月 19 日
Use can use fprintf and fileparts functions for each line of your output:
fid = fopen('target.txt','a+');
for i = 1:length(srcFiles)
% separate file name into path, name and extension
[pathstr,name,ext] = fileparts(srcFiles(i).name);
% add only the path and name (no extension)
fprintf(fid,'%s\n',fullfile(pathstr,name));
end
fclose(fid);
If you don't want to include the filepath, you can just remove pathstr from the fprintf statement. If there is no pathstr in your filename, it will be an empty string so won't matter anyway.
Hope this helps, Wil
  1 件のコメント
Ameligege
Ameligege 2015 年 3 月 19 日
Millions of thanks to you I really appreciate your help

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by