Matlab 版 (精华区)
发信人: zjliu (秋天的萝卜), 信区: Matlab
标 题: 可以查看文件夹或者是文件的大小的程序2.0
发信站: 哈工大紫丁香 (Sun Apr 4 15:06:07 2004), 站内信件
前一程序的另一版本
function bytesize=bytesizedirorf2(varargin)
% 可以查看包括子目录的文件夹的总共大小
% 或者是单个文件的大小
% bytesize=bytesizedirorf
% bytesize=bytesizedirorf(directory)
% bytesize=bytesizedirorf(filename,1)
% Calculate the total size in a directory or a file
%
% dirorfile: the root directory or the file you want to look up
% default :pwd
% flag: 0-----dirorfile is a root directory(default)
% 1-----dirorfile is a filename
% bytesize: the totle space being used of the directory or the file
%
% example1: bytes=bytesizedirorf(pwd);
% example2:
% bytes=bytesizedirorf('D:\Programs\MATLAB6p5p1\bin\matlab.bat',1);
%
% Copyright:Genial @ USTC
% Email:JGRong@ustc.edu
% 2004.3.31
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
switch nargin,
case 0,
dirorfile=pwd;
flag=0;
case 1,
dirorfile=varargin{1};
flag=0;
case 2,
dirorfile=varargin{1};
flag=varargin{2};
otherwise,
warning('Too many input Argument!');
help bytesizedirorf;
return;
end
if(~flag)
dirinfo=dir(dirorfile);
if isempty(dirinfo)
error(['Can not find the directory:',dirorfile]);
end
num=length(dirinfo);
bytesize = sum([dirinfo.bytes]);
dir_index = find([dirinfo.isdir] == 1);
for k = 3 : length(dir_index)
bytesize = bytesize +...
bytesizedirorf([dirorfile,'\',getfield(dirinfo(dir_index(k)),'name')]);
end
else
fileinfo=dir(dirorfile);
if isempty(fileinfo)
error(['Can not find the file:',dirorfile]);
end
bytesize=getfield(fileinfo,'bytes');
end
--
╔═══════════════════╗
║★★★★★友谊第一 比赛第二★★★★★║
╚═══════════════════╝
※ 来源:.哈工大紫丁香 bbs.hit.edu.cn [FROM: 202.118.229.162]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.259毫秒