Search code examples
phpfileexecls

How to make the linux/macOS command " .ls >> files.txt " run at php using exec()?


I Just wanna to list all files and subdirectories and store this list in file ... in MS-DOS, Linux and MAC OS, the command line -- .ls( or .dir) >> files.txt -- would give me what I want ... But, how to make a php script run it ?

if I use (on php)

exec ('ls >> files.txt');

I will get a error like this: Warning: Unexpected character in input: '' (ASCII=28) state=0 in /Applications/XAMPP/xamppfiles/htdocs/DjUtilities/makeLabels.php on line 29

...

please, any idea ???

The use of this will be to set labels with the musics in a cd, here, divided by directories... I wanna to get any cd's (subdirectories) and list the files (the tracks) to make a label with the track list....

So, The initial idea was to create a file with these data and then, process the data to make the labels... any better way to do that will be very welcome !!


Solution

  • You can use 'opendir' and 'readdir' to do that, both native php commands...