Convert script using system commands from Linux to Windows

6 次查看(过去 30 天)
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);

采纳的回答

Walter Roberson
Walter Roberson 2023-2-11
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 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by