Cleanup Images Dir

I have a site that once had 9000 products

i deleted them from the admin by selecting

the dir and clicking delete …



however the script timed out before getting done …



the cart is supposed to have like 200 product now …



but if i ftp into the site and look in the /images/detailed dir

there is over 2000 images still there …





how can i clean up the dead images …???

no one knows how to clean up Orphan images.

The only way I can think of would be by ftp.

But how would you know which images were being used and which ones were “orphans” if you use ftp.

[quote name=‘Lyn’]But how would you know which images were being used and which ones were “orphans” if you use ftp.[/QUOTE]







exaclty …



thats the problem i have … since the images are renamed i have no idea which are part of my products and which are junk …



since the images are about 400mb total … i really need to find a way to delete all the images that are not linked to a product…

It’s a simple process actually. I haven’t been using 2.0.x but if the import/export is working properly then this is what you need to do.


  1. Make sure you do not have any images backed up: /images/backup
  2. From admin, export your detailed and thumbnail images.(You can export detailed images only, if you want the thumbnails to be recreated when you reimport) This will create /images/backup with the current images you are using. Save the export file.
  3. From the server, delete files in /images/detailed, /images/product, /images/thumbnails.
  4. From admin, import your images using the file created in step 2
  5. Optional: You can delete /images/backup if you want to.

Does this also work with any images you have for the different options when you have a product with options?

I’m not sure Lyn. I do not use options so I do not know how it works in the background.

teksigns, did this work?

Hi,



What is this folder for?



images/backup ?



When the backup folder inside images is created and why?



Can I delete this folder without any conflicts?



I also have one backup folder inside var/downloads/backup, has this one the same use for cs-cart with the one above(images/backup) ?



thanks for any help, I 'm facing web space issue…

[quote name=‘teksigns’]I have a site that once had 9000 products

i deleted them from the admin by selecting

the dir and clicking delete …



however the script timed out before getting done …



the cart is supposed to have like 200 product now …



but if i ftp into the site and look in the /images/detailed dir

there is over 2000 images still there …





how can i clean up the dead images …???[/QUOTE]



this bash script would remove all files that are same as files in current dir

if you need to also delete the ones cs-cart makes when its already there…



like bob.jpg

bob2390823098490284.jpg



then -name "${newfile}.jpg"

instead of

-name “${newfile}.jpg”



but carefull if you have short 1 or 2 or 3 letter files…mod the maxlength

so basically if you are in



httpdocs/temporary/supplier1images/ HERE

then it will remove same filename from



httpdocs/images/


httpdocs/thumbnails/

httpdocs/icons/


etc

so you can DROP your products and reimport + reimport pictures…

You can also just reimport pictures IF AND ONLY IF you dont have additional images… else they ADD meaning you will get more then you bargained for.





USE THIS at your own risk… BACKUP / BACKUP THE BACKUP… and backup again





#!/bin/sh

ls -1d .jpg 2>/dev/null | while read file

do



newfile=ls $file| sed 's/\.[^.]*$//'|tr '[A-Z]' '[a-z]'





#echo “NEW FILE : $newfile”

echo “Removing from all places :${newfile}”





let “maxlen=3”



strlen=${#newfile}



if [ $strlen -gt 3 ]; then

find …/…/images/
-name “${newfile}*.jpg” | xargs /bin/rm -f

find …/…/images/* -name “${newfile}.jpg”

else

echo no

fi

sleep 0



done