MATLAB Answers

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

1 view (last 30 days)
Ameligege on 19 Mar 2015
Commented: Ameligege on 19 Mar 2015
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
Here is the output that I want
I am Waiting for any help............

Accepted Answer

wil on 19 Mar 2015
Edited: wil on 19 Mar 2015
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)
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

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by