필터 지우기
필터 지우기

Open files with certain file size

조회 수: 2 (최근 30일)
David du Preez
David du Preez 2017년 3월 31일
댓글: David du Preez 2017년 4월 1일
Hi I have hundreds of files with a similar name. I can open them all with the following code:
% Open the HDF5 File.
for k = 1:365
FILE_NAME = sprintf('MLS-Aura_L2GP-O3_v04-20-c01_2006d%03d.SUB.he5',k);
file_id = H5F.open(FILE_NAME, 'H5F_ACC_RDONLY', 'H5P_DEFAULT');
end
now I only want to open files when the file size is greater than 37 KB. How do I do that ?

채택된 답변

KSSV
KSSV 2017년 3월 31일
files = dir('your file extension') ;
% loop for each file
for i = 1:length(files)
if files(i).bytes*1000 > 37 % if file size is > 37 do what you want
filename = files(i).name ;
disp(filename)
%open your file do what you want
end
end
  댓글 수: 1
David du Preez
David du Preez 2017년 4월 1일
Great thanks. Here is my updated script:
for i = 1:length(files)
if files(i).bytes > 50000
filename = files(i).name;
disp(filename)
%open files with data
file_data = H5F.open(filename,'H5F_ACC_RDONLY','H5P_DEFAULT');
%Data field for data wanted
DATAFIELD_NAME = 'HDFEOS/SWATHS/O3 column/Data Fields/L2gpValue';
data_id = H5D.open(file_data,DATAFIELD_NAME);
%Time component
TIME_NAME='HDFEOS/SWATHS/O3 column/Geolocation Fields/Time';
time_id = H5D.open(file_data,TIME_NAME);
data1=H5D.read (data_id,'H5T_NATIVE_DOUBLE', 'H5S_ALL', 'H5S_ALL', ...
'H5P_DEFAULT');
time=H5D.read(time_id,'H5T_NATIVE_DOUBLE', 'H5S_ALL', 'H5S_ALL',...
'H5P_DEFAULT');
time1lvl=datestr(datevec(datenum(1993,1,1,0,0,0)+time(1)/86400));
end
end
How do I change so the output files (data1,time and time1lvl) are not over written each time?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Other Formats에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by