Search code examples
loopscoldfusiondirectoryimage-manipulationcoldfusion-8

Looping through all images within multiple directories in ColdFusion


I'm working on an image manipulation script to create smaller thumbnail images of the images that are already on the server.

The directory structure that I need to search through is as follows:

Content
    -Att1
        -image1
            -imgA1_1.png
            -imgA1_1_large.png
        -image2
            -imgA1_2.png
            -imgA2_large.png
        -image3
            -imgA1_3.png
            -imgA1_3_large.png
    -Att2
        -image1
            -imgA2_1.png
            -imgA2_1_large.png
        -image2
            -imgA2_2.png
            -imgA2_2_large.png
        -image3
            -imgA2_3.png
            -imgA2_3_large.png
    -Att3
        -image1
            -imgA3_1.png
            -imgA3_1_large.png
        -image2
            -imgA3_2.png
            -imgA3_2_large.png
        -image3
            -imgA3_3.png
            -imgA3_3_large.png

etc...

So what I would like to to is be able to loop through all of the images shown above and if the dimensions of that image exceed 500-500 then create a thumbnail that is 100-100.

Is there any way of doing this without looping through each directory?


Solution

  • cfdirectory has a recurse attribute. This will loop through all the folders, but it won't require you to write code to loop through all the folders

    <cfdirectory directory="yourDirectory" recurse="yes">