* * *

Author Topic: Reading a directory  (Read 299 times)

sigipa

  • New member
  • *
  • Posts: 5
Reading a directory
« on: March 29, 2017, 08:18:38 am »
Hello All,

I'm new to pascal, so please forgive my ignorance. I've been searching for a function to read a directory. I'm aware of FindFirst, but I don't need any kind of search testing or the overhead of that. Is there a function that will just read a directory ala libc opendir/readdir?

Thanks,
-S

GetMem

  • Hero Member
  • *****
  • Posts: 1991
Re: Reading a directory
« Reply #1 on: March 29, 2017, 08:22:51 am »
Quote
Hello All,

I'm new to pascal, so please forgive my ignorance. I've been searching for a function to read a directory. I'm aware of FindFirst, but I don't need any kind of search testing or the overhead of that. Is there a function that will just read a directory ala libc opendir/readdir?

Hi sigipa,

FindAllFiles from fileutil perhaps?
http://wiki.freepascal.org/FindAllFiles

sigipa

  • New member
  • *
  • Posts: 5
Re: Reading a directory
« Reply #2 on: March 29, 2017, 08:32:07 am »
Hi,

I saw that, but I fear that it will be doing some unnecessary testing on the filter (or lack thereof). I'll take a look at the source to see if that is an issue. I appreciate the pointer.

Thanks,
-S

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5244
Re: Reading a directory
« Reply #3 on: March 29, 2017, 10:05:53 am »
findfirst/next on unix is roughly opendir/readdir + stat per file.

readdir is pages of code so a simple test on an integer value to check if it is a dir is not measurable. The stat thing might be measurable though, but that is the price of portability.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus