MATLAB Answers

question regarding 'copyfile' function from folder to folder

1 view (last 30 days)
Yu Li
Yu Li on 4 Aug 2019
Commented: Yu Li on 4 Aug 2019
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.

Accepted Answer

Jan
Jan on 4 Aug 2019
Edited: Jan on 4 Aug 2019
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

Yu Li
Yu Li on 4 Aug 2019
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.

More Answers (0)

Sign in to answer this question.