copyfile skips files?
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello everyone!
I want to create copies of specific files in a new directory. They are coming out of over 500 different subfolder, so I don't want to do it manually.
I have loaded and accessed data within all of them, so I know they exist. For some reason, not all files make it to the destination folder, but I'm not getting an error message. I also have plenty of space on my drive, so that can't be the problem either.
ddir = uigetdir;
AllFiles = dir(fullfile(ddir, '**', 'DT_data*mat'));
destination = 'C:\Users\XXXXX\Desktop\tempFigData';
for i = 1:length(AllFiles)
sourcefile = fullfile(AllFiles(i).folder, AllFiles(i).name);
copyfile(sourcefile, destination);
end
Does anyone have an idea what could be the problem here?
3 commentaires
dpb
le 19 Avr 2020
Do a dir() on the target destination and compare to the AllFiles original.
dDest=dir(fullfile(destination, '**', 'DT_data*mat'));
SrcDestDiff=setdiff({AllFiles.name},{dDest.name})
Réponses (1)
Image Analyst
le 19 Avr 2020
Try this:
% Get top level folder.
ddir = uigetdir(pwd);
filePattern = fullfile(ddir, '**', 'DT_data*.mat');
AllFiles = dir(filePattern);
destination = 'C:\Users\XXXXX\Desktop\tempFigData';
if ~isfolder(destination)
mkdir(destination);
end
fprintf('Found %d files.\n', length(AllFiles));
if length(AllFiles) == 0
warningMessage = sprintf('Did not find any files matching %s', filePattern);
uiwait(errordlg(warningMessage));
return;
end
for i = 1:length(AllFiles)
sourceFileName = fullfile(AllFiles(i).folder, AllFiles(i).name);
destinationFileName = fullfile(destination, AllFiles(i).name);
fprintf('Copying file %s\n to %s\n', sourceFileName, destinationFileName);
% copyfile(sourceFileName, destination);
end
Now what do you see?
7 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!