Jump to content

Recommended Posts

I have a directory with a way too many images in it. Gigabytes of jpeg photos. Normally, I wouldn't think this a major problem. But, processing the directory list takes an eternity. Even from shell, If I try to delete a number of them with a wildcard, I get "argument list too long".

 

Well, I know this is causing the cron script that deletes old images to grind the system to a halt. 4am or not, it's just too much. So, how do you separate such a large number of images into, say, ten separate directories, and still have the file system able to find them when asked for?

 

This is all running on a LAMP server. All these images are tied to a database with over 6,000 records each. Each record could contain as many as 12 images. Filenames are simply a nine digit number followed by .jpg. Ideas much appreciated.

Link to comment
https://forums.phpfreaks.com/topic/65735-solved-too-many-files/
Share on other sites

Something like this should work:

 

steviewdr@burkesys:~$ cat deletesomefiles.sh

#!/bin/bash

 

for file in `ls /var/tmp/ | head -n 50`

do

        rm $file

done

 

 

That script (chmod 755) will delete the first 50 files in the directory. You might be able to bump the 50, up to 500. Note there are special backticks ` used above for the ls.

 

-steve

Link to comment
https://forums.phpfreaks.com/topic/65735-solved-too-many-files/#findComment-328641
Share on other sites

So, how do you separate such a large number of images into, say, ten separate directories, and still have the file system able to find them when asked for?

 

Each record could contain as many as 12 images.

 

I would place each records files within there own sub directory named after the record id. This way you would have 1 directory per record, and each directory would contain up to 12 images. Much easier to handle and still very easy to locate the images.

 

 

Link to comment
https://forums.phpfreaks.com/topic/65735-solved-too-many-files/#findComment-328816
Share on other sites

I would place each records files within there own sub directory named after the record id. This way you would have 1 directory per record, and each directory would contain up to 12 images. Much easier to handle and still very easy to locate the images.

 

Wow, it's one of those "why didn't I think of that" million dollar ideas.

 

Thanks!

 

Question, though, can PHP unlink a directory, or would I have to loop through the contents, unlinking each one, then rmdir'ing the directory?

Link to comment
https://forums.phpfreaks.com/topic/65735-solved-too-many-files/#findComment-328854
Share on other sites

Question, though, can PHP unlink a directory, or would I have to loop through the contents, unlinking each one, then rmdir'ing the directory?

 

I think you can use unlink() on directories, but only if they're empty. You could just do exec("rm -rf {$directory}"); though.

 

Edit: No, you can't use unlink(), you must use rmdir() (must still be empty though).

Link to comment
https://forums.phpfreaks.com/topic/65735-solved-too-many-files/#findComment-328973
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.