use of movefile to move files to another dir
Mostrar comentarios más antiguos
Hello, e.g. I have some files named
ab01.sun, cd023.sun, sdf45.sun, wad23.sun
I want to move a file into a subfolder after its work is done. I made a string of filenames and a code like this.
ls_al = dir;
justfiles = ls_al(~[ls_al.isdir]); %only for files
savepath = Y:\ykumkar\MyWork\;
for k = 1:length(justfiles)
filename = justfiles(k).name;
[MyOut, X] = MyFunctionyk(filename);
sp=[savepath char(filename) '.mat'];
save(sp, 'MyOut', 'X');
Now I want to move the first file to a subfolder 'done_files' after the function is run and the output is saved and so on.
movefile ('justfiles(k)', './done_files/'); % need help here
disp 'Done for the file justfiles(k)'; % need help here
end
Respuestas (2)
Fangjun Jiang
el 28 de Ag. de 2011
0 votos
What is your question? A few things.
- savepath='Y:\ykumkar\MyWork\';% need to have single quotes for sting assignment
- sp=[savepath,filename,'.mat'); %no need to use char() since filename is already a string
- movefile(filename,fullfile('./done_files/',filename));
YOGESH
el 28 de Ag. de 2011
3 comentarios
Fangjun Jiang
el 29 de Ag. de 2011
movefile() is basically movefile(source, destination). You can try the movefile() command in Command Window to understand it's syntax and make sure it works. Also, make sure if your function MyFunctionyk(filename) opens the file using fopen(), make sure it is closed using fclose().
Fangjun Jiang
el 29 de Ag. de 2011
The error seems to come from fullfile(). Take a look at help fullfile to see how it should be used. It basically put path and file name together. You can also use [PathStr,filesep,FileName] too, where filesep is defined by MATLAB. type 'filesep' to see it.
YOGESH
el 29 de Ag. de 2011
Categorías
Más información sobre Filename Construction en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!