Author Topic: How to read all the files of a folder?  (Read 887 times)

0 Members and 1 Guest are viewing this topic.

Offline As de Espada

  • Soldat Beta Team
  • Veteran
  • ******
  • Posts: 1493
  • Mapper
    • My maps
How to read all the files of a folder?
« on: November 05, 2011, 02:42:51 am »
I was just wondering... I want to do a ReadFile for each file in a folder. Is there any way to do that? (of course I don't know those files at compilation time)

It's not important right now, but I am curious.
All my maps | my latest map: SoldatX Racing Mappack
me making a map on youtube: ctf_FastMade

Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: How to read all the files of a folder?
« Reply #1 on: November 05, 2011, 04:25:21 am »
nope

edit: you could use shell_exec() and do some console magics, but that is OS-dependent and unsafe i think

Offline JotEmI

  • Soldier
  • **
  • Posts: 188
Re: How to read all the files of a folder?
« Reply #2 on: November 05, 2011, 06:35:32 am »
I think shell_exec() doesn't return the actual result of executed command, only -1 if it failed and 0 if it succeeded. So something like shell_exec('ls -al') won't retrieve list of files. You could make a bash script that writes the list of all files in specified folder to a txt file which you could then read through ScriptCore. Only I'm not sure if you can run a bash script with shell_exec().

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: How to read all the files of a folder?
« Reply #3 on: November 05, 2011, 02:05:47 pm »
shell_exec most likely means that you can.
If you're not paying for something, you're not the customer; you're the product being sold.
- Andrew Lewis

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

Offline jrgp

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 5037
Re: How to read all the files of a folder?
« Reply #4 on: November 06, 2011, 09:05:47 pm »
Only I'm not sure if you can run a bash script with shell_exec().

Under unix/linux, it doesn't make a difference if the program you try to run is a script or a binary; if it is a script and has the necessary shebang line as well as executable permissions, I'm sure shell_exec would work fine.

However if it doesn't already the script core should really have a glob() utility, like most languages do.
« Last Edit: November 06, 2011, 09:07:32 pm by jrgp »
There are other worlds than these