: : Hello!
: : I was vorking in BP7 'till now but i want to try Dev-Pascal with FreePascal compiler. The problem is that BP creates the text files next to the exe when no path is specified, Dev-Pas creates it in their own folder.
: :
: : Ex:
: : Assign(f,'something.txt');
: : ReWrite(f);
: : {...}
: : Close(f);
: :
: : If the source file is in c:\Projects\New\ then BP creates something.txt in c:\Projects\New\ (c:\Projects\New\something.txt). In Dev-Pascal's case it's C:\Dev-Pas\something.txt.
: : So how can i set Dev-Pascal to create the text files given without path next to the soure/exe?
: :
: I'm not familiar with Dev-Pascal, so the functions might be different, but the trick is usable.
:
: After the user typed the filename, you check if it contains a path (by checking for backslashes for example). If it doesn't contain one, you add the path to the executable. In TP this can be found using the ParamStr(0) function (giving the full filename). You then need to remove the executable's filename to leave the path. In Delphi that can be done using the ExtractFilePath() function, but it isn't hard to code it yourself.
:
To make it more simple there already is a proceure to extract the path of the exe file from the full path. It is in the dos unit and here is it's reference:
Procedure FSplit (path: pathstr; var dir: dirstr; var name: namestr; var ext: extstr);
And here is the example of how to use it to extract the exe path.
program test;
uses dos;
var path, dirstr, name, ext: string[255];
f: text;
begin
path:=paramstr(0);
FSplit(path, dirstr, name, ext);
writeln('Program path: ', dirstr);
assign(f, dirstr);
rewrite(f);
write(f, 'This is a test.');
close(f);
readln
end.
Hope it helps.