用FileSetAttr函数简单function FileSetAttr(const FileName: string; Attr: Integer): Integer;procedure TFMForm.Properties1Click(Sender: TObject);
var
  Attributes, NewAttributes: Word;
begin
  with FileAttrForm do
  begin
    FileDirName.Caption := FileList.Items[FileList.ItemIndex];
    { set box caption }
    PathName.Caption := FileList.Directory;
    { show directory name }
    ChangeDate.Caption := 
      DateTimeToStr(FileDateToDateTime(FileAge(FileList.FileName)));
    Attributes := FileGetAttr(FileDirName.Caption);
    { read file attributes }
    ReadOnly.Checked := (Attributes and faReadOnly) = faReadOnly;
    Archive.Checked := (Attributes and faArchive) = faArchive;
    System.Checked := (Attributes and faSysFile) = faSysFile;
    Hidden.Checked := (Attributes and faHidden) = faHidden;
    if ShowModal <> id_Cancel then { execute dialog box }
    begin
      NewAttributes := Attributes;
      { start with original attributes }
      if ReadOnly.Checked then
        NewAttributes := NewAttributes or faReadOnly
      else 
        NewAttributes := NewAttributes andnot faReadOnly;
      if Archive.Checked then
        NewAttributes := NewAttributes or faArchive
      else 
        NewAttributes := NewAttributes andnot faArchive;
      if System.Checked then 
        NewAttributes := NewAttributes or faSysFile
      else 
        NewAttributes := NewAttributes andnot faSysFile;
      if Hidden.Checked then 
        NewAttributes := NewAttributes or faHidden
      else 
        NewAttributes := NewAttributes andnot faHidden;
      if NewAttributes <> Attributes then { if anything changed... }
        FileSetAttr(FileDirName.Caption, NewAttributes);
         { ...write the new values }
    end;
  end;
end;

解决方案 »

  1.   

    不是BOOL CopyFile(
      LPCTSTR lpExistingFileName,
                              // pointer to name of an existing file
      LPCTSTR lpNewFileName,  // pointer to filename to copy to
      BOOL bFailIfExists      // flag for operation if file exists
    );
     ---------
    //delphi:
    copyfile(pchar('c:\aaa.xml'),pchar('c:\aaa_back.xml'),true);
      

  2.   

    当目标文件已存在,且文件的属性为只读时,CopyFile可能会不成功,所以要先用SetFileAttribute把它的属性设置为可读。
    CopyFile(原文件名,目标文件名,是否覆盖)
    最后一个参数指是不是要覆盖已存在的文件。