Problem with saving to textfile

Why does my file end up in c:\documents instead of the folder of my program???

My procedure looks like this:

Procedure TForm1.SaveMyFile;
Var
F : TextFile;
Begin

   AssignFile(F,'myFile.txt');
   Rewrite(F);
   Try
      writeLn(F,'bla bla');
      .
      .
      .
   finally
     CloseFile(F);
   end;
end;

Hope you can help me :)
Retep
retepAsked:
Who is Participating?
 
lzCommented:
It depends on how your program was started what becomes the current directory. You cannot rely that the current directory is where your *.exe is. So, instead of

AssignFile(F,'myFile.txt');

use the following line

AssignFile(F, ExtractFilePath(Application.ExeName) + 'myFile.txt');

This will in all cases store the file in the same directory as your *.exe.
0
 
geobulCommented:
Hi,
The reason is not in the procedure above. Maybe there is a value 'Start in: c:\documents' in the shortcut. Maybe you change current directory somewhere in the code before saving the file.

Regards, Geo
0
 
retepAuthor Commented:
Thanks :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.