• Hey guys,

    I need to get a list of all the file links (or the FTP path) from a directory and it’s sub-folder files too.

    For example:
    /image/01
    /image/02
    /image/03

    I need all the image links/paths from all the folders within the /image/ folder.
    It would save me a huge time with a task I’ve been stuck for a few days..

Viewing 1 replies (of 1 total)
  • Hi,
    Have you tried scandir?

    It returns an array of filenames within a specified directory. you could do

    function get_filenames(){
      return scandir(get_template_directory() . '/image');
    }
    

    then, loop through that array with foreach to create links.

    For subfolders, you could check whether each entry in the returned array has a .jpg, .png, or similar file extension. If not, call scandir on the subdirectory and add the result of that call to the initial array. Rinse and repeat.

    Hope this helps!

    • This reply was modified 4 years, 10 months ago by Peter Steele.
    • This reply was modified 4 years, 10 months ago by Peter Steele.
Viewing 1 replies (of 1 total)
  • The topic ‘How to get a list of all the file URLs from a folder & sub-folder?’ is closed to new replies.