Error in BEAR toolbox initexcel copyfile(s​ourcefile,​destinatio​nfile)

11 次查看(过去 30 天)
Hi All,
When running the following piece of code from the BEAR toolbox from the european central bank:
delete([pref.datapath filesep 'results' filesep pref.results_sub '.xlsx']);
% then copy the blank excel file from the files to the data folder
sourcefile=[pwd filesep 'results.xlsx'];
destinationfile=[pref.datapath filesep 'results' filesep pref.results_sub '.xlsx'];
line 7: copyfile(sourcefile,destinationfile);
I get the following error
Error using copyfile
The system cannot find the path specified.
Error in initexcel (line 7)
copyfile(sourcefile,destinationfile);
However I downloaded the toolbox from the internet including all files in it thus I do not understand why it cannot find the files. I can find the results.xlsx file in the folder files.

回答(1 个)

Piyush Kumar
Piyush Kumar 2024-8-29
From the error message - "The system cannot find the path specified.", it seems to be a path issue.
Also, from "I can find the results.xlsx file in the folder files.", I assume that the file to be copied is present in the folder.
You can try these troubleshooting steps -
  • Verify Paths: Ensure that both sourcefile and destinationfile paths are correct. You can do this by printing them out before the copyfile command:
disp(sourcefile);
disp(destinationfile);
  • Check Current Directory: Make sure that the current directory (pwd) is what you expect it to be. Sometimes, the script might be running in a different directory than you think.
  • Existence of Source File: Confirm that the results.xlsx file actually exists in the directory returned by pwd.
if exist(sourcefile, 'file') ~= 2
error('Source file does not exist.');
end
  • Permissions: Ensure that you have the necessary permissions to read from the source directory and write to the destination directory.
  • Create Destination Directory: If the destination directory does not exist, you might need to create it before copying the file.
  • Add the files and folders involved to the MATLAB search path before copying.
Refer the following links -

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by