System('cp'... ) cant find the existing file: "no such file or directory"
조회 수: 1 (최근 30일)
이전 댓글 표시
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
dpb
2022년 10월 23일
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
2022년 10월 24일
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?
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!