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

조회 수: 5 (최근 30일)
john karli
john karli 2022년 3월 8일
답변: Simon Chan 2022년 3월 8일
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에서 Spectral Measurements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by