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

1 回表示 (過去 30 日間)
D.geo
D.geo 2022 年 10 月 23 日
コメント済み: Jan 2022 年 10 月 24 日
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
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
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 ExchangeFile Operations についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by