Matlab 版 (精华区)

发信人: zjliu (秋天的萝卜), 信区: Matlab
标  题: 可以查看文件夹或者是文件的大小的程序1.0
发信站: 哈工大紫丁香 (Sun Apr  4 15:05:12 2004), 站内信件

function bytesize=bytesizedirorf(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=0;
    for k=3:num % because of the first and second of dirinfo will be and.
        tmpbytes=getfield(dirinfo(k),'bytes') ;
        if(getfield(dirinfo(k),'isdir'))
            
tmpbytes=bytesizedirorf([dirorfile,'\',getfield(dirinfo(k),'name')]);
        end
        bytesize=bytesize+tmpbytes;
    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)
页面执行时间:5.726毫秒