Convert script using system commands from Linux to Windows
6 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Walter Roberson
on 11 Feb 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 Comments
More Answers (0)
See Also
Categories
Find more on File Operations 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!