首页  编辑  

获得目录的大小

Tags: /C#/文件目录操作/   Date Created:

public long DirectorySize( string strDirectory)

{

    if ( ! Directory . Exists(strDirectory)) return 0 ;

    long vReturn = 0 ;

    foreach ( string vFile in Directory . GetFiles(strDirectory))

   {

        FileInfo vFileInfo = new FileInfo (vFile);

       vReturn += vFileInfo . Length;

   }

    foreach ( string vDirectory in Directory . GetDirectories(strDirectory))

       vReturn += DirectorySize(vDirectory);

    return vReturn;

}