![]() |
|
|
#1
|
|||
|
|||
|
здравствуйте!помогите!!!надо скопировать один файл(текстовый) в другой с атрибутами только для чтения используя функции:
CreateFile CloseHandle ReadFile WriteFile могу ли я просто его скопировать, а потом у второго файла просто -поменять атрибут???? вот что - то сделала... Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure SetAttribut( Path: string; r, h, s, a: char );
var
At: integer;
begin
At := FileGetAttr( Path );
if r = '+' then At := At or faReadOnly;
if h = '-' then At := At or faHidden;
if s = '+' then At := At or faSysFile;
if a = '+' then At := At or faArchive;
FileSetAttr( Path, At );
end;
procedure TForm1.Button1Click(Sender: TObject);
var
f: TextFile;
begin
if copyfile('c:1.txt','c:2.txt',true) then
showmessage('Файл успешно скопирован!')
else showmessage('Неудача!');
end;
procedure TForm1.Button2Click(Sender: TObject);
var
At: integer;
begin
SetAttribut( 'c:\2.txt', '+', '-', ' ', ' ' );
end;
end. |
|
#2
|
||||
|
||||
|
Можешь конечно, только это кака:
Код:
procedure SetAttribut( Path: string; r, h, s, a: char ); var At: integer; begin At := FileGetAttr( Path ); if r = '+' then At := At or faReadOnly; if h = '-' then At := At or faHidden; if s = '+' then At := At or faSysFile; if a = '+' then At := At or faArchive; FileSetAttr( Path, At ); end; ... procedure TForm1.Button2Click(Sender: TObject); var At: integer; begin SetAttribut( 'c:\2.txt', '+', '-', ' ', ' ' ); end; так "красивее": Код:
type TAttr = (atReadOnly, atHidden, atSysFile, atArchive); TAttSet = set of TAttr; procedure SetAttribut(Path: string; Attr : TAttrSet); var At: integer; begin // At := FileGetAttr(Path); At := 0; if atReadOnly in Attr then At := At or faReadOnly; if atHidden in Attr then At := At or faHidden; if atSysFile in Attr then At := At or faSysFile; if atArchive in Attrthen At := At or faArchive; FileSetAttr(Path, At); end; procedure TForm1.Button2Click(Sender: TObject); begin SetAttribut( 'c:\2.txt', [atReadOnly]); end; Последний раз редактировалось angvelem, 27.11.2011 в 22:28. |
| Этот пользователь сказал Спасибо angvelem за это полезное сообщение: | ||
tesler (28.02.2012)
| ||
|
#3
|
|||
|
|||
|
хоть я и поздно отвечаю, но всё равно спасибо, вы мне тогда очень помогли!здесь есть какая-нибудь кнопка "автоматическое спасибо"???(которая ваш рейтинг повышает)
|
| Этот пользователь сказал Спасибо tesler за это полезное сообщение: | ||
ResTaVRaToR_96 (12.04.2013)
| ||