Why is trailing back space removed from my folder name?
Show older comments
I have a subfolder named .\results (I give the whole name)
Allowing the user to change it I have name app.defOutLoc as default and the app.OutLoc once confirmed.
app.OutLoc = app.defOutLoc;
K>> defOutLoc
defOutLoc =
"C:\Users\CPSLab\Documents\OdorChoiceDev\results\"
K>> app.OutLoc
ans =
"C:\Users\CPSLab\Documents\OdorChoiceDev\results"
So when I add the folder name to file name I end up saving \resultsMyFileName.txt in the parent folder
Who asked you to trim my \? and what do I do now?
I've added at some points
% Don't forget the ending \
app.OutLoc = append(app.OutLoc,"\");
but now need to chase down every time I do an assignment and add it back!
You would think it could at least be done right here where I build the name:
app.StartSessionTime = ...
char(datetime('now','Format',"_yyMMdd_HHmmss"));
baseFileName = append(app.MouseName.Value, ...
app.StartSessionTime);
app.SessionFileName = append(app.OutLoc, ...
"MC_",baseFileName,"_session.m");
app.SessionFile = fopen(app.SessionFileName,'at'); % allow appending
I suppose there is some special way to combine file parts instead of append where ML put it back that I missed.
OK I found fullfile() Now to get it to properly put all the pieces together. Like this?
app.SessionFileName = fullfile(app.OutLoc, append("MC_",baseFileName,"_session"),"m";
Accepted Answer
More Answers (0)
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!