有没有获得和设置文件属性的api函数,不想用delphi的那个FileGetAttr和FileSetAttr

解决方案 »

  1.   

    procedure TForm1.Button14Click(Sender: TObject);
    var zz:twin32finddata;zz1,zz2,s,z7,z8,z9,z10:string;h:thandle;z1:pchar;i:integer;
    z4,z2,z3,z6:tfiletime;z5:dword;
    //cardinal;
    begin
    i:=1;
    memo1.Lines.Clear;
    h:=windows.FindFirstFile(pchar('d:*.*'),zz);
    if h<>invalid_handle_value then
    begin
    while windows.FindNextFile(h,zz) do
    begin
    s:=' ';
    z2:=zz.ftCreationTime;
    z3:=zz.ftLastAccessTime;
    z4:=zz.ftLastWriteTime;
    filetimetolocalfiletime(z2,z6);
    filetimetodosdatetime(z6,longrec(z5).Hi,longrec(z5).Lo);
    z7:=datetostr(filedatetodatetime(z5));
    filetimetolocalfiletime(z3,z6);
    filetimetodosdatetime(z6,longrec(z5).Hi,longrec(z5).Lo);
    z8:=datetostr(filedatetodatetime(z5));
    filetimetolocalfiletime(z4,z6);
    filetimetodosdatetime(z6,longrec(z5).Hi,longrec(z5).Lo);
    z9:=datetostr(filedatetodatetime(z5));
    //showmessage(zz.cFileName);
    //showmessage(zz.cAlternateFileName);
    zz2:=inttostr(zz.dwFileAttributes);
    z10:=zz.cFileName;
    //showmessage(zz2);
    if (zz.dwFileAttributes) and (FILE_ATTRIBUTE_ARCHIVE)=FILE_ATTRIBUTE_ARCHIVE then  S := s+'A';
    if (zz.dwFileAttributes) and (FILE_ATTRIBUTE_COMPRESSED)=FILE_ATTRIBUTE_COMPRESSED then S:=s+ 'C';
    if (zz.dwFileAttributes) and (FILE_ATTRIBUTE_DIRECTORY)=FILE_ATTRIBUTE_DIRECTORY then S := s+'D';
    if (zz.dwFileAttributes) and (FILE_ATTRIBUTE_HIDDEN)=FILE_ATTRIBUTE_HIDDEN then S := s+'H';
    if (zz.dwFileAttributes) and (FILE_ATTRIBUTE_NORMAL)=FILE_ATTRIBUTE_NORMAL then S := s+'N';
    if (zz.dwFileAttributes) and (FILE_ATTRIBUTE_READONLY) =FILE_ATTRIBUTE_READONLY then S :=s+'R';
    if (zz.dwFileAttributes) and (FILE_ATTRIBUTE_SYSTEM) =FILE_ATTRIBUTE_SYSTEM  then S := s+'S';
    if (zz.dwFileAttributes) and (FILE_ATTRIBUTE_TEMPORARY)=FILE_ATTRIBUTE_TEMPORARY then S :=s+'T';
    memo1.Lines.Add('name:'+zz.cFileName+':xh:  '+inttostr(i)+':attri:'+s+':size:'+inttostr(zz.nFileSizeLow)+'kb:'
    +z7+':'+z8+':'+z9);
    if z10<>'.' then inc(i);
    end;
    end;
    windows.FindClose(h);
    showmessage(inttostr(i-1));
    以上为取得文件属性、大小、个数程序
      

  2.   

    BOOL GetFileInformationByHandle(    HANDLE hFile,  // handle of file 
        LPBY_HANDLE_FILE_INFORMATION lpFileInformation  // address of structure 
       );typedef struct _BY_HANDLE_FILE_INFORMATION { // bhfi  
        DWORD    dwFileAttributes; 
        FILETIME ftCreationTime; 
        FILETIME ftLastAccessTime; 
        FILETIME ftLastWriteTime; 
        DWORD    dwVolumeSerialNumber; 
        DWORD    nFileSizeHigh; 
        DWORD    nFileSizeLow; 
        DWORD    nNumberOfLinks; 
        DWORD    nFileIndexHigh; 
        DWORD    nFileIndexLow; 
    } BY_HANDLE_FILE_INFORMATION;
      

  3.   

    if setfileattributes('c:\123.dbf',file_attribute_readonly) then showmessage('ok');
      

  4.   

    那不如直接用dos下面自带得命令行attrib
    winexec(pchar('command.com /c attrib +r filename'),sw_hide);
      

  5.   

    to  WWWWA(aaaa) 、yansea(思宏) :
    象你们的这种方法能不能得到象win2000 ad下的压缩等什么属性
      

  6.   

    我的方法就是在WIN2000 SP3下通过的。
      

  7.   

    这个办法最简单
    winexec(pchar('command.com /c attrib +r filename'),sw_hide);
      

  8.   

    GetFileAttributes 或者 GetFileAttributesEx
    简单地要死……