System('cp'... ) cant find the existing file: "no such file or directory"

1 Ansicht (letzte 30 Tage)
D.geo
D.geo am 23 Okt. 2022
Kommentiert: Jan am 24 Okt. 2022
using the for loop below returns "no such file or directory". I ran the matlab script in the folder, with and without the path. I also ran the program out of the folder with the below path, and still recieved the same message. The file definitely exsist and is within the directory. I am using a MAC and MATLABR2022a. Thanks for the help!
for i= 1:length(chr)
structvariableA=dir([station '.channel.' chr(i,1:7) '*.SAC'])
if str2num(charvariableA(a,1:6)) > str2num(stringvariable(i,3:8))
a = a +1
fldtfID = system(['cp -R ' '~/Desktop/Folder/Datafolder/subdatafolder/' structvariableA.name ' ' charvariableA(a,1:12) 'x.' lower(charvariable) 'e'])
else
fldtfID = system(['cp -R ' '~/Desktop/Folder/Datafolder/subdatafolder/' structvariableA.name ' ' charvariableA(a,1:12) 'x.' lower(charvariable) 'e'])
end
end
  7 Kommentare
dpb
dpb am 23 Okt. 2022
I "know nuthink!" about MAC OS/Linux/derivatives, but I presume like the other OS if one uses a directory as a target, it will copy to that location.
However, it would seem simpler to not have to build the OS command but to use the MATLAB built in movefile which works that way and also without building the string commands but with inherent MATLAB variables.
Jan
Jan am 24 Okt. 2022
Are you sure, that "~/Desktop/Folder/Datafolder/subdatafolder/" is the current folder in Matlab? Prefer to work with absolute paths instead:
folder = '~/Desktop/Folder/Datafolder/subdatafolder/';
...
structvariableA = dir(fullfile(folder, [station '.channel.' chr(i,1:7) '*.SAC']));
The rest of the code looks very artificial: The names of the variables, the mixing of CHAR and string types, an IF/ELSE, which calls the same command in both branches, using a SYSTEM call instead of the built-in movefile (as dpb has mentioned)? Is this an experiment or used for productive work?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by