Search code examples
perlcgicgi-bin

Delete all *.jpg in folder


How do I delete files within a temp folder at only have the .jpg extension.

Here is what I tried;

unlink("../httpdocs/Temp/*.jpg);

Solution

  • You need to apply the glob function to the pattern, for example:

    unlink glob "../httpdocs/Temp/*.jpg";
    

    This is covered in the unlink and glob docs. Unlink itself expects a list of files to process. The glob function will, to quote the docs:

    In list context, returns a (possibly empty) list of filename expansions on the value of EXPR such as the standard Unix shell /bin/csh would do.