Problem with saving to textfile

Posted on 2000-05-05
Last Modified: 2010-04-04
Why does my file end up in c:\documents instead of the folder of my program???

My procedure looks like this:

Procedure TForm1.SaveMyFile;
F : TextFile;

      writeLn(F,'bla bla');

Hope you can help me :)
Question by:retep
LVL 17

Expert Comment

ID: 2781101
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

Accepted Solution

lz earned 50 total points
ID: 2781107
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


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.

Author Comment

ID: 2781249
Thanks :)

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now