how to copy a specific files from one folder to another folder?

4 次查看(过去 30 天)
I have Folder name as 8PSK and it contain 5000 files. but i need first 3500 files (frame_snr-108PSK101: frame_snr-108PSK3500) to copy to another folder.
8PSK
frame_snr-108PSK101
frame_snr-108PSK102
frame_snr-108PSK103
...... frame_snr-108PSK5000
i have tried the below code but it gives me random 3500 file, Although i need first files from 101 to 3500
filePattern = fullfile('E:\SNR-Dataset\DATA-11-time\time-data-training\8PSK\8PSK', '*.mat');
dest = 'E:\SNR-Dataset\DATA-11-time\time-data-training\8PSK\8PSK\8PSK'
% Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 101 : 3600
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
copyfile( fullFileName, dest)
end
Please Assist

回答(1 个)

Simon Chan
Simon Chan 2022-3-8
Try the following:
filePattern = fullfile('E:\SNR-Dataset\DATA-11-time\time-data-training\8PSK\8PSK', '*.mat');
dest = 'E:\SNR-Dataset\DATA-11-time\time-data-training\8PSK\8PSK\8PSK'
% Change to whatever pattern you need.
theFiles = dir(filePattern);
%
nameFiles = {theFiles.name};
[num,pos] = sort(cellfun(@(x) str2double(extractBetween(x,'frame_snr-108PSK','.txt')),nameFiles));
startnum = 101;
finishnum = 3600;
fileindex = pos(num>=startnum & num<=finishnum);
for k = 1:numel(fileindex)
baseFileName = theFiles(fileindex(k)).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
copyfile( fullFileName, dest)
end

类别

Help CenterFile Exchange 中查找有关 Install Products 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by