Need help moving files based on name
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a series of wav files from a recorder which records six 1-minute files each hour. When I retrieve my data it is in files sorted by month with as many as 4400 files in total. The files are named like this: 20190901T04500.wav (2019-09-01 04:50):
I would like to sort each day into a different folder like this:
I know the movefile command but the problem here is I want to move the file based up the 7th and 8th digits (day). I.e., I want the script to place all files with digits 7-8 = "09" into a folder called "9".
댓글 수: 0
답변 (1개)
Shunichi Kusano
2019년 9월 11일
Hi Benjamin,
you can pick up the filename with the specific day as the followings:
for i = 1:30 % from 1st to 30th
searchStr = sprintf('201909%02d*', i); % %02i means two digits integer with 0 padding
fileInfo = dir(searchStr);
fileInfo.name % just for cheking
targetFolder = sprintf('%d',i) % no padding
% movefile for each
filenames = cat(1, fileInfo.name);
for filei = 1:size(filenames,1)
filename = filenames(filei,:);
disp(filename) % just for cheking
if exist(targetFolder) == 7 % if the targetFolder is the existing folder
movefile(filename, targetFolder);
end
end
end
Perhaps, this codes will work well. But, just in case, please try without movefile at once in your environment.
Hope this helps.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Measurements and Spatial Audio에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!