Copyfile/ movefile when filenames are not directly available
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Afzal Mohammed
el 28 de Mzo. de 2020
Comentada: Afzal Mohammed
el 29 de Mzo. de 2020
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!
Respuesta aceptada
Peng Li
el 28 de Mzo. de 2020
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 comentarios
Peng Li
el 29 de Mzo. de 2020
If you need to create a folder called newFolder, use mkdir('newFolder'); first to create a folder named newFolder at the current directory.
Más respuestas (1)
Walter Roberson
el 28 de Mzo. de 2020
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.
Ver también
Categorías
Más información sobre Database Toolbox en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!