Name must be a text scalar
Afficher commentaires plus anciens
Hi,
I wan to use the datetime() function to name a folder. Moreover, I want to change the format with the replace() function and later access this folder via dir(). However, I get an error that says "Name must be a text scalar". I suppose the reason lies in the replace function. Is there any other way to do this?
actual_time = datestr(datetime('now')); % holt die aktuelle Zeit
files = dir([actual_time '\*.txt']); % works
actual_time = fullfile(replace(actual_time, ':', '-'))
files = dir([actual_time '\*.txt']); % error
2 commentaires
They both work here (I also replaced deprecated DATESTR with the recommended CHAR).
Note that you should use FULLFILE instead of concatenating text together.
actual_time = char(datetime('now'))
S1 = dir([actual_time '\*.txt']) % Should use FULLFILE here
actual_time = fullfile(replace(actual_time, ':', '-'))
S2 = dir([actual_time '\*.txt']) % Should use FULLFILE here
"Is there any other way to do this?"
Explicitly specify the DATETIME format:
DT = datetime('now','Format','uuuu-MM-dd HH-mm-ss')
S = dir(fullfile(char(DT),'*.txt'))
Marco Pedata
le 7 Juin 2023
Réponses (0)
Catégories
En savoir plus sur Undirected Graphs dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!