MATLAB Answers

Yu Li
0

question regarding 'copyfile' function from folder to folder

Asked by Yu Li
on 4 Aug 2019
Latest activity Commented on by Yu Li
on 4 Aug 2019
Accepted Answer by Jan
Hi:
I tried to use 'coypfile' function from folder to folder.
assuming I have file a.txt, b.txt in folder 'A', and a.txt, b.txt, c.txt in folder 'B', using command: copyfile('A','B'), looks like it has some behaviors below:
  • it will only not replace folder 'B' with 'A', it seems like copy files in to folder 'A' to folder 'B', i.e. the file 'c.txt' in folder 'B' will not be removed
  • copyfile will overwrite the files having the same name in folder 'B' by files from folder 'A', i.e. the file 'a.txt' and 'b.txt' in folder 'B' will be overwrite by 'a.txt' and 'b.txt' from folder 'A'
but I could not find any illustration regarding this behavior anywhere, am I correct with the observation described above?
Thanks!
Yu

  0 Comments

Sign in to comment.

1 Answer

Answer by Jan
on 4 Aug 2019
Edited by Jan
on 4 Aug 2019
 Accepted Answer

This is exactly, what you find in the documentation. Please read:
help copyfile
doc copyfile
[SUCCESS,MESSAGE,MESSAGEID] = copyfile(SOURCE, DESTINATION) attempts to
copy SOURCE to DESTINATION. If SOURCE constitutes a directory or
multiple files and DESTINATION does not exist, copyfile attempts to
create DESTINATION as a directory and copy SOURCE to DESTINATION. If
SOURCE constitutes a directory or multiple files and DESTINATION exists
as a directory, copyfile attempts to copy SOURCE to DESTINATION.
This means, that copyfile copies the files from the source directory to the destination directory. This sounds intuitive for a function, which is called "copy file".

  1 Comment

Hi Jan:
Thanks for your reply. I read the link below, but looks like it is not as detail as what shows in your answer.
Thanks!
Yu

Sign in to comment.