给文件重命名 (50分)

  • 主题发起人 主题发起人 fossil
  • 开始时间 开始时间
F

fossil

Unregistered / Unconfirmed
GUEST, unregistred user!


varDataRec: TDataRec;
BackFile: File of TDataRec;
FileName: String;
begin
FileName:= GetCurrentDir + '/1.dat';
AssignFile (BackFile,FileName);
Rewrite(BackFile);
......
s := GetCurrentDir+ '/bb.dat';
RenameFile(FileName, s);//不能给文件重命名??????????????
Closefile(BackFlie);
end;






var BackFileRec: TBackFileRec; 类型文件

BackFile: File of TBackFileRec;
怎么READ?
 
1、重命名时不能打开文件。
2、用BlockRead读
 
先关闭文件,再重命名
varDataRec: TDataRec;
BackFile: File of TDataRec;
FileName: String;
begin
FileName:= GetCurrentDir + '/1.dat';
AssignFile (BackFile,FileName);
Rewrite(BackFile);
......
Closefile(BackFlie);
s := GetCurrentDir+ '/bb.dat';
RenameFile(FileName, s);
end;
 
varDataRec: TDataRec;
BackFile: File of TDataRec;
FileName: String;
begin
FileName:= GetCurrentDir + '/1.dat';
[blue]//AssignFile (BackFile,FileName);
//Rewrite(BackFile);
......[/blue]
s := GetCurrentDir+ '/bb.dat';
RenameFile(FileName, s);//不能给文件重命名??????????????
[blue]//Closefile(BackFlie);[/blue]
end;
 
楼上的:第二个问题能举例子?
 
摘自Delphi帮助:
var
FromF, ToF: file;
NumRead, NumWritten: Integer;
Buf: array[1..2048] of Char;
begin
if OpenDialog1.Execute then { Display Open dialog box }
begin
AssignFile(FromF, OpenDialog1.FileName);
Reset(FromF, 1); { Record size = 1 }
if SaveDialog1.Execute then { Display Save dialog box}
begin
AssignFile(ToF, SaveDialog1.FileName); { Open output file }
Rewrite(ToF, 1); { Record size = 1 }
Canvas.TextOut(10, 10, 'Copying ' + IntToStr(FileSize(FromF))
+ ' bytes...');
repeat
BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
BlockWrite(ToF, Buf, NumRead, NumWritten);
until (NumRead = 0) or (NumWritten <> NumRead);
CloseFile(FromF);
CloseFile(ToF);
end;
end;
end;
 
多人接受答案了。
 

BlockRead(FromF, Buf, SizeOf(Buf), NumRead);NumRead参数是什么意思?
 
后退
顶部