Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-07

Creating a directory in the home directory

6 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Dave Coventry

I'm trying to create a temporary directory called ~/.mydirectory

When I run this code:

DirectoryPath:='~/.mydirectory/';
  if not DirectoryExists(DirectoryPath) then
  try
    ForceDirectories(DirectoryPath);
  except
    MessageDlg('A temporary path could not be
constructed.'+DirectoryPath+#13+#10+
      'Please correct this and try again', mtWarning, [mbOk], 0);
  end;

It appears that the directory (~/mydirectory) does exist although I cannot find it.

What am I doing wrong?

Reply by email

dmitry boyarintsev
to Dave Coventry
Dave Coventry wrote
I couldn't really say, to be honest. But that piece of code was working a year or so ago...

I'm not sure.
As far as I know "~" is actually shell specific symbol.

i.e. try to compile the following code:

begin
  if ParamCount>0 then writeln(ParamStr(1))
end.

and launch the program from terminal: "./test ~" (no quotes) instead of "~" you'll your home path. The "~" is handled by the shell (as an environment variable) and converted to the correct full-path before passing it to the application.

If you try the same command line on Window, you'll get "~" printed. Because window's shells (except for cygwin, mingwin) are not aware of unix shells conventions home-char "~".

I guess RTL/FCL/LCL is working cross-platform way and doesn't treat "~" in any special way, so the same code would work identical on any system.

thanks,
dmitry

Reply by email