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

4 ビュー (過去 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 Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by