遍历一个文件夹下的文件,如果下面的文件有大于20M的就警告。

解决方案 »

  1.   

    The GetFileSize function retrieves the size, in bytes, of the specified file. DWORD GetFileSize(    HANDLE hFile, // handle of file to get size of
        LPDWORD lpFileSizeHigh  // address of high-order word for file size
       );
     ParametershFileSpecifies an open handle of the file whose size is being returned. The handle must have been created with either GENERIC_READ or GENERIC_WRITE access to the file. lpFileSizeHighPoints to the variable where the high-order word of the file size is returned. This parameter can be NULL if the application does not require the high-order word.
      

  2.   

    //------------------------------------------------------------------------------
    //
    //  取指定文件的大小
    //
    //  参数   :
    //         FileName     :       指定的文件名(带路径)
    //
    //  返回值 :
    //         成功: 返回文件的大小 (单位 : KB)
    //         失败: 返回 -1
    //
    //------------------------------------------------------------------------------
    function GetFileSize(const FileName: String): LongInt;
    var
      F: File of Byte;
    begin
      //文件关联
      AssignFile(F, FileName);
      Try
        Reset(F);           //打开文件
        Try
          //返回大小 KB
          Result := FileSize(F) DIV 1024;
        Finally;
          CloseFile(F);     //关闭文件
        end;
      Except;
        Result := -1;       //失败
      end;
    end;
      

  3.   

    改一下就可以满足你的要求function GetFileSize(const FileName: String): Boolean;
    var
      F: File of Byte;
    begin
      //文件关联
      AssignFile(F, FileName);
      Try
        Reset(F);           //打开文件
        Try
          //返回大小 KB
          Result := FileSize(F) > (1024 * 1024 * > 20);
        Finally;
          CloseFile(F);     //关闭文件
        end;
      Except;
        Result := False;       //失败
      end;
    end;
      

  4.   

    取文件大小其实就是个API嘛,遍历文件夹的算法有现成的,搜搜!再把俩玩艺揉在一起就可以了!
    来骗分啊,呵呵......
      

  5.   

    取文件大小别人都给了,我给一个遍历文件夹函数吧。
    function SearchFile( RootPath, FileName: String; var lstFile: TStrings ):Boolean;//---------------------------------------------------------------------------
    //
    //      查找一个目录下的文件,写在lstFile
    //
    //---------------------------------------------------------------------------
    function SearchFile( RootPath, FileName :String; var lstFile: TStrings ):Boolean;
    var
      FileRec     : TSearchRec;
    begin
      if RootPath[Length(RootPath)] <>'\' then
         RootPath := RootPath +'\';  if ( FindFirst( RootPath + FileName, faAnyFile, FileRec ) =0 ) then
      begin
        lstFile.Add( RootPath + FileRec.Name );
        while ( FindNext( FileRec ) = 0 ) do
        begin
          lstFile.Add( RootPath + FileRec.Name );
        end;
      end;
      FindClose( FileRec );  Result := True;
    end;使用方法:
    var
      lstFiles :TString;
    begin
      lstFiles := TStringList.Create;
      SearchFile( 'C:\', *.*, lstFiles );
      
      // c盘下的所有文件名称都在lstFiles中了。
      // 文件名一就是:lstFiles.Strings[0];
      // 文件名二就是:lstFiles.Strings[1];
    end;