Convert script using system commands from Linux to Windows
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Elise
le 11 Fév 2023
Réponse apportée : Walter Roberson
le 11 Fév 2023
Aiming to use this code on a Windows computer (it works with no issues on MATLAB online but want to run it on the desktop version). ivtfile is a netcdf files. Getting errors saying 'ls is not a recognised internal or external command'. I have tried replacing 'ls' with 'dir' but it does not give me the correct output.
[~,cmdout]=system(['ls -1 ',ivtfile]);
ivtfiles=textscan(cmdout,'%s','delimiter','\n');
ivtfiles=ivtfiles{1};
nfile=numel(ivtfiles);
[outdir,~,~]=fileparts(outfile);
0 commentaires
Réponse acceptée
Walter Roberson
le 11 Fév 2023
Unless ivtfile has wildcard patterns recognized by your linux shell, use
dinfo = dir(ivtfile);
outdirs = {dinfo.folder};
ivtfilenames = fullfile(outdirs, {dinfo.name});
nfile = length(filenames)
ivtfilenames will be the fully-qualified file names. outdirs will be a cell array of folder names. You would typically only create a separate array to hold all of them if you had the case that the input ivtfile was a pattern that matched several directories, such as
ivtfile = 'ivt*/*.xlsx';
intending to match xlsx files in multiple folders each of which begins with "ivt"
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur File Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!