In the Delphi program, to move the file we can use the function : MoveFile(lpExistingFileName, lpNewFileName: PChar): Boolean;
lpExistingFileName : The file will be copied
lpNewFileName : Destination file (complete with paths)
Example:
Create a Form with an Edit, 1 DriveComboBox, 1 DirectoryListBox1, and 2 Button. Perform double-clicking the Button1 component and button2, write the following program listing :
procedure TF_MoveFile.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then Edit1.Text:=OpenDialog1.FileName;
end;
procedure TF_MoveFile.Button2Click(Sender: TObject);
begin
if Movefile(pchar(Edit1.Text),
pchar(DirectoryListBox1.Directory+'\'+extractfilename(Edit1.Text)))=true
then showmessage('Successfully move the file')
else showmessage('Failed to move file');
end;
No comments:
Post a Comment