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!