How to filter images and exclude filenames that include hyphen and image size in Filezilla?

StackOverflow https://stackoverflow.com/questions/23481214

  •  16-07-2023
  •  | 
  •  

Question

I have a folder in my server that contains several images resized by WordPress. I want to upload only the images that are not resized. Here's an example:

File Names :

2CVictoria_and_Albert_Museum_London-708x400.jpg
2CVictoria_and_Albert_Museum_London-336x190.jpg
2CVictoria_and_Albert_Museum_London.jpg

I want only files that end with .jpg without the -708x400 and 336x190

2CVictoria_and_Albert_Museum_London.jpg

How to create a filter in Filezilla that will ignore all the images that have been resized and show only the original image? Please if you can put all the filter rules.

Was it helpful?

Solution

Based on your criteria, this should work.

^[[:alnum:]_]+\.jpg$

and after the edit requested:

^[[:alnum:]_-]+[^-0-9x]+\.jpg

and after the second edit requested:

^[[:alnum:]_-]+[^x]{5}\.jpg

I don't have Filezilla installed at the moment, but Filezilla uses POSIX regular expressions. This means we can't use lookaheads, but that shouldn't be a problem.

The expression uses a character class [[:alnum:]_] with a quantifier, allowing it to match any number of letters, digits and underscores. Then we match a period, jpg and the end of the string, so any suffix using a dash will fail.

In the second expression, before the .jpg, we make sure to match any number of characters that are not dashes, digits or xs.

In the third expression, the [^x]{5} is a bit of a hack: it ensures there is no "x" character in the last five characters, therefore excluding files ending in 300x225.jpg for instance. This would also exclude some false-negatives, such as myphotox.jpg as well as short files such as abc.jpg

One way to get around the short file problem is, which accepts all four-letter filenames that don't include xs. Still a hack.

^[[:alnum:]_-]+[^x]{5}\.jpg|^[^x]{1,4}\.jpg

If there are exceptions, let me know so we can tweak the regex.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top