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

1 Ansicht (letzte 30 Tage)
tommy laarhoven
tommy laarhoven am 25 Mai 2021
Beantwortet: Piyush Kumar am 29 Aug. 2024
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.

Antworten (1)

Piyush Kumar
Piyush Kumar am 29 Aug. 2024
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 -

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by