How to use Variables in movefile or copyfile ?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Lets say I want to move or copy file from one folder to another. I am using movefile to do this, but the thing is that I want to automate this process. So I have a variable A = 'D:\Olddirectory\File.txt' which contains a path to my file and a variable B = 'D:\Newdirectory'. So the syntax says :
copyfile('D:\Olddirectory\File.txt','D:\Newdirectory');
% That way it works well, but when i use it this way:
copyfile([A,',',B]);
% which should give the same output
% it doesn`t work at all and give me an error: "Error using copyfile. No matching files were found."
I`ll be thankfull for any Help.
4 Kommentare
Paolo
am 30 Mai 2018
No worries, you can select Stephen's answer to accept the solution and close this question.
Stephen23
am 30 Mai 2018
"which should give the same output"
I don't see why that should give the same output: in the first case you call copyfile with two inputs, in the second you call it with just one input (and input that clearly does not follow any of the permitted syntaxes given in the documentation).
Akzeptierte Antwort
Stephen23
am 30 Mai 2018
Bearbeitet: Stephen23
am 30 Mai 2018
copyfile(A,B)
[] is a concatenation operator, so when you do [A,',',B] you form one char vector with the contents of A and B joined together with one comma in between, and you then supply that one char vector as one input argument to copyfile.
But copyfile requires two input arguments (for what you are trying to do), not one (when you provide copyfile with just one argument this must be only the source file/s only).
3 Kommentare
Stephen23
am 30 Mai 2018
@Pavlo M: you might like to do the introductory tutorials, which explain how to call functions (and other useful basic concepts that you will need to know when using MATLAB):
Even if you have some experience I recommend that you give them a try.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!