تبلیغات
آموزش مطلب - چاپ محتویات یک دایرکتوری

آموزش مطلب

چاپ محتویات یک دایرکتوری

دوشنبه 6 شهریور 1385

تا حالا شده کخ بخوهایم محتویات یک دایرکتوری را چاپ کنید؟واسه من که خیلی پیش آمده.

برنامه زیر این کار را انجام می دهد و فهرست محتویات یم دایرکنپتوری را در یک فایل rtf می نویسد.

function get_dir_file_name
hfig = figure('unit','pixel','pos',[200,200,300,100],'menu','none');
uicontrol('pos',[10, 10,70 20],'style','checkbox','string','Directory','tag','dir')
uicontrol('pos',[250, 60,40 30],'string','Go','callback',@getname)
uicontrol('pos',[10, 40,70 20],'style','checkbox','string','Size','tag','size')
uicontrol('pos',[10, 70,70 20],'style','checkbox','string','Dime','tag','date')

function getname(hobject,eventdata,hhandle)
Vdir = get(findall(0,'tag','dir'),'value');
Vsize = get(findall(0,'tag','size'),'value');
Vdate = get(findall(0,'tag','date'),'value');
dir_name = uigetdir;
dir_file = dir(dir_name);
num_file = size(dir_file);
fid=fopen('temp.rtf','w');
controlchar =0;
for i=3:num_file(1)
if ~ dir_file(i).isdir
fprintf(fid,'%s\t',dir_file(i).name);
if Vdate
fprintf(fid,'%s\t',dir_file(i).date);
end
if Vsize
fprintf(fid,'%s\t',num2str(dir_file(i).bytes));
end
fprintf(fid,'%s\n','');
elseif (dir_file(i).isdir & Vdir)
fprintf(fid,'%s\t',dir_file(i).name);
if Vdate
fprintf(fid,'%s\t',dir_file(i).date);
end
fprintf(fid,'%s\t','directory');
fprintf(fid,'%s\n','');
end
end
fclose(fid);
 

 



[ دوشنبه 6 شهریور 1385 - 01:08 ق.ظ ]
[ویرایش شده در : شنبه 21 مهر 1386 - 11:10 ق.ظ]

[ پیام ()|| امین باشی ] [خودم , ] [+]


نوشته های پیشین ...