Copyfile/ movefile when filenames are not directly available
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello Everyone,
I have two .xlsx files in a folder, I want to copy/ move those .xlsx files to a different folder but the user is not aware of file names which are stored in a workspace variable of the same Matlab program.
As shown below: 'flagged' is a workspace variable of my program which has file names. I want to copy/ move those specific files to a separate folder.
I tried following but it's not working
copyfile flagged(i).name newFolder
Please advise.
Thanks!
채택된 답변
Peng Li
2020년 3월 28일
flagged is a cell so you couldn’t access it using parentheses and dot motion.
flagged{i} is your ith element in flagged. For example flagged{1} will be myFile.xlsx. If you want to move it somewhere you may also need the full directory as well unless it’s in the current directory.
댓글 수: 3
Peng Li
2020년 3월 29일
If you need to create a folder called newFolder, use mkdir('newFolder'); first to create a folder named newFolder at the current directory.
추가 답변 (1개)
Walter Roberson
2020년 3월 28일
Assuming that newFolder is the name of a variable that stores the destination folder name:
copyfile(flagged(i).name, newFolder)
However I would recommend that you should be using fullfile() and should be using exist() to test to be sure that the file exists before you attempt to copy it.
댓글 수: 5
참고 항목
카테고리
Help Center 및 File Exchange에서 Database Toolbox에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!