Reputation: 573
How can I make my Delphi 7 program save itself into a new location. For example the program is saved on my flash stick then when I run it I want it to save itself in c:\user \ (user name)
The above is the original question.
This is the code I tried using. The program runs perfectly but when I check the folder it was supposed to save it in it does not appear there.
procedure TForm5.FormActivate(Sender: TObject);
var source, dest : string;
begin
Source := 'project1.exe';
Dest := 'C:\Users\Craig\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup';
CopyFile(PChar(Source), PChar(Dest), False);
end;
Thanks for your help.
Upvotes: 2
Views: 1312
Reputation: 612914
Read the executable file name from Application.ExeName. And then call CopyFile to perform the copy.
Source := Application.ExeName;
Dest := ...;
CopyFile(PChar(Source), PChar(Dest), False);
Regarding your update:
CopyFile
, you need to check the return value.You want something like this:
Source := 'project1.exe';
Dest := 'C:\Users\...\Startup\project1.exe';
if not CopyFile(PChar(Source), PChar(Dest), False) then
RaiseLastOSError;
Upvotes: 3
Reputation: 1838
try this:
CopyFile(PChar(C:\OldFile.exe), PChar(C:\NewFile.exe), true);
Upvotes: 0