I have a folder including sub-folders in my Windows PC where I have multiple files of images with different dimensions with standard formatted names as shown below.
- first-image-name.jpg
- first-image-name-72x72.jpg
- first-image-name-150x150.jpg
- first-image-name-250x250.jpg
- first-image-name-300x300.jpg
- first-image-name-400x400.jpg
- first-image-name-1024x1024.jpg
- second-image-name.png
- second-image-name-72x72.png
- second-image-name-150x150.png
- second-image-name-250x250.png
- second-image-name-300x300.png
- second-image-name-400x400.png
- second-image-name-1024x1024.png
Now I want to delete all those image files that are of different sizes as shown in their name and should leave the original one only.
For that, I tried many queries as shared below but non of these are working...
Windows PowerShell:
Get-ChildItem $Path | Where{$_.Name -Match '.*[0-9]+x[0-9]+.\(jpg\|png\|jpeg\)$'} | Remove-Item
Windows CMD:
find -type f -regex '.*[0-9]+x[0-9]+.\(jpg\|png\|jpeg\)$' -delete
find -name '.*[0-9]+x[0-9]+.\(jpg\|png\|jpeg\)$' -delete
None of the above is working so let me know what I am doing wrong...??? Please remember I have to use it as recursive as I have many folders inside the main folder too.