Moving files (excel) from a folder A to B

1 回表示 (過去 30 日間)
Jake
Jake 2016 年 12 月 28 日
コメント済み: Image Analyst 2016 年 12 月 28 日
Hi,
I have some excel files that have to be moved after the work is done.
Using movefile, I tried moving the file but didn't work..
filename = 'holdings_today.csv';
movingfrom = '\\C:\Program Files\MATLAB';
destination = '\\C:\Program Files\MATLAB\excels';
movefile(filename , movingfrom , destination )
Is there anything that I miss important here?
Thanks for your help in advance,
Jake
  1 件のコメント
per isakson
per isakson 2016 年 12 月 28 日
You missed the left hand side of
[SUCCESS,MESSAGE,MESSAGEID] = movefile(SOURCE,DESTINATION)
which probably will help you understand why it didn't work.

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

採用された回答

Image Analyst
Image Analyst 2016 年 12 月 28 日
Try getting rid of the double backslashes at the start. And while you're at it might as well convert all of them to forward slashes to avoid potential future problems. Windows can understand forward slashes just fine. Trust me.
  2 件のコメント
Jake
Jake 2016 年 12 月 28 日
Thanks for your help!!!!
Image Analyst
Image Analyst 2016 年 12 月 28 日
Jake, you should be more robust like checking if the folder exists already and creating it if it does not exist yet.
movingfrom = 'C:/Program Files/MATLAB';
if ~exist(movingfrom, 'dir')
mkdir(movingfrom);
end
destination = 'C:/Program Files/MATLAB/excels';
if ~exist(destination, 'dir')
% This will throw an error or fail because
% Windows does not allow you to create a folder or file below Program Files.
mkdir(destination);
end
Your folder creation and moving to a folder "C:/Program Files/MATLAB/excels" will fail because Windows does not let you create files or folders under the Program Files folder. You'll have to pick a different folder.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by