On a mac, how do you copy a folder with files on the desktop to a subfolder in the directory on my search path?

3 ビュー (過去 30 日間)
I'm working with a mac and I'm trying to write a program which involves copying a directory (with the files I need) to either the directory on my search path or a sub-directory in that directory. I've tried a number of commands, but something like /Users/arthur/Desktop/the directory or /Users/arthur/Desktop/directory/file results in an error -- no such file or directory. It is crucial that I be able to do this or --- no program. Please help.

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 1 月 7 日
SRC = '/Users/arthur/Desktop/the directory'
DST = ' /Users/arthur/MATLAB/Area51/YetiImages';
if ~exist(SRC, 'dir')
error('Source not a directory: "%s"', SRC);
end
if ~exist(DST, 'dir')
try
mkdir(DST);
catch ME
error('Destination not a directory and could not be created: "%s"', DST);
end
end
cmd = sprintf('cd ''%s''; find . -depth -print | cpio -pdm ''%s''', SRC, DST);
fprintf('About to start command: "%s"\n', cmd);
try
[status, result] = system(cmd);
if status == 0
fprintf('I think it might have worked!\n');
else
fprintf('Something odd happened. System said:\n');
fprintf('%s\n', result);
end
catch ME
fprintf('Something went wrong when executing the command.\n');
end
  5 件のコメント
Walter Roberson
Walter Roberson 2018 年 1 月 7 日
My code does copy. cpio -p copies files, and cp -R copies.
Arthur Shapiro
Arthur Shapiro 2018 年 1 月 8 日
I ran it exactly as you suggested and no files showed up in YetiImages until I added the copyfile command. Since I'm a total novice with MATLAB, I wouldn't presume to suggest why that happened. Also, thanks so much for your add suggestions. I'll try them.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by