Create multiple copies of one file in multiple directories with different names
조회 수: 7 (최근 30일)
이전 댓글 표시
I want to create multiple folders. Let's say, the names of folders are- Folder 1, Folder 2, Folder 3 and so on.
In each folder, I would like to copy file "A.txt" and rename the file to "A_1.txt", "A_2.txt", "A_3.txt" and so on. How can I do that?
댓글 수: 0
채택된 답변
Fabio Freschi
2022년 9월 28일
Try this.
Note: the file A.txt must be in the current folder
% data
N = 10;
dirName = 'Folder';
fileName = 'A';
% loop
for i = 1:N
% create directory
mkdir(strcat(dirName,num2str(i)));
% copy file
copyfile('A.txt',strcat(dirName,num2str(i),'/',fileName,'_',num2str(i),'.txt'));
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Files and Folders에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!