Convert script using system commands from Linux to Windows

6 vues (au cours des 30 derniers jours)
Elise
Elise 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);

Réponse acceptée

Walter Roberson
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"

Plus de réponses (0)

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!

Translated by