Recent

Author Topic: LCL? - Working with files and directory's  (Read 413 times)

djongepier

  • New Member
  • *
  • Posts: 12
LCL? - Working with files and directory's
« on: May 14, 2025, 11:36:38 am »
Hello all,

I'm having some trouble finding the procedures related to file handling.
These are the things I want to do:
- Check if file/directory exists
- Find exe's in the PATH variable
- Read from environment variables

For context, I have some experience with Python's pathlib, this might color my expectations.

Lot's of things are kind of new and I am not really familiar yet with the style of naming I guess.
« Last Edit: May 14, 2025, 11:43:18 am by djongepier »

Handoko

  • Hero Member
  • *****
  • Posts: 5445
  • My goal: build my own game engine using Lazarus
Re: LCL? - Working with files and directory's
« Reply #1 on: May 14, 2025, 11:48:15 am »
These should be what you need:

https://www.freepascal.org/docs-html/rtl/sysutils/fileexists.html
https://www.freepascal.org/docs-html/rtl/sysutils/getenvironmentvariable.html

Lot's of things are kind of new and I am not really familiar yet with the style of naming I guess.

Just ask, people here are very nice and helpful.
If you're new in Lazarus or programming in general, you can download, try and study these demos:

https://wiki.freepascal.org/Portal:HowTo_Demos

Fibonacci

  • Hero Member
  • *****
  • Posts: 757
  • Internal Error Hunter
Re: LCL? - Working with files and directory's
« Reply #2 on: May 14, 2025, 11:50:36 am »
- Find exe's in the PATH variable

Code: Pascal  [Select][+][-]
  1. uses SysUtils;
  2.  
  3. function where(file_: unicodestring): unicodestring;
  4. var
  5.   u: unicodestring;
  6. begin
  7.   result := '';
  8.   for u in unicodestring(GetEnvironmentVariable('PATH')).Split([';']) do
  9.     if FileExists(IncludeTrailingBackslash(u)+file_) then
  10.       exit(IncludeTrailingBackslash(u)+file_);
  11. end;
  12.  
  13. begin
  14.   writeln(where('fpc.exe'));
  15.   writeln(where('calc.exe'));
  16.   readln;
  17. end.

Nimbus

  • Jr. Member
  • **
  • Posts: 57
Re: LCL? - Working with files and directory's
« Reply #3 on: May 14, 2025, 11:53:27 am »

Fibonacci

  • Hero Member
  • *****
  • Posts: 757
  • Internal Error Hunter
Re: LCL? - Working with files and directory's
« Reply #4 on: May 14, 2025, 11:59:54 am »

Thaddy

  • Hero Member
  • *****
  • Posts: 17213
  • Ceterum censeo Trump esse delendam
Re: LCL? - Working with files and directory's
« Reply #5 on: May 14, 2025, 12:52:07 pm »
Code: Pascal  [Select][+][-]
  1. {$macro on}{$define FindExecutables:= ExeSearch}
Will help to find it.. %)
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

djongepier

  • New Member
  • *
  • Posts: 12
Re: LCL? - Working with files and directory's
« Reply #6 on: May 14, 2025, 12:59:24 pm »
There's ExeSearch in SysUtils
https://www.freepascal.org/docs-html/rtl/sysutils/exesearch.html

That's what I need, although, I use the SysUtils unit, but the identifier is not found. Which leads me to believe it's in some other unit?

djongepier

  • New Member
  • *
  • Posts: 12
Re: LCL? - Working with files and directory's
« Reply #7 on: May 14, 2025, 01:03:15 pm »
Nevermind, got it!

Somehow my brain had a fart and added the C in ExeSearch, like so 'ExecSearch' which does not work.

Look at the screenshot.

 

TinyPortal © 2005-2018