Copy a folder into another

조회 수: 18 (최근 30일)
rbarata
rbarata 2015년 11월 1일
댓글: rbarata 2015년 11월 2일
Hello, new user here.
Very basic question...I want to copy a folder which is on the same level (hence outside) of the current folder and paste it in a subfolder of the current folder. I've tried it and by using the status function the result is "1". So, it was a successful operation. The problem is that the only thing it was coppied were the files inside the copied folder and not the folder and its contents.
How can I do it.
Thanks

채택된 답변

the cyclist
the cyclist 2015년 11월 1일
copyfile('../../oldDirectoryName','newDirectoryName')
Set the new name to be identical to the old one, if you want to retain the same name.
Use more or fewer sets of '../', depending on the number of levels away it is in the directory structure.
  댓글 수: 1
rbarata
rbarata 2015년 11월 2일
I could see where I was going wrong, or what I was not doing. I need to specify the copied folder name in the destiny path. This is a strange behaviour because when I copy something, I copy everything, even the folder name. But this might be useful to copy the contents in a new folder without using mkdir.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2015년 11월 1일
The folder that is one level up from the current folder appears to designate the parent of the current folder. You want to copy it and all its children into a new folder in the current folder. As the current folder is a child of its parent, that means the current folder must be copied into a child of itself, and since it contains that child, the child folder must be copied into the child folder, and since that is a child of the current folder it has to be copied...
In other words, you are creating an infinite loop.
Do you possibly mean you want to copy a folder that has the same level as the current folder, like C:\A and C:\B are at the same level?
  댓글 수: 1
rbarata
rbarata 2015년 11월 1일
Yes, what I meant was copying a folder at the same level that the current folder. My mistake in the first post (already corrected).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by