michaellunsford Posted August 19, 2007 Share Posted August 19, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/65735-solved-too-many-files/ Share on other sites More sharing options...
steviewdr Posted August 20, 2007 Share Posted August 20, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/65735-solved-too-many-files/#findComment-328641 Share on other sites More sharing options...
trq Posted August 20, 2007 Share Posted August 20, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/65735-solved-too-many-files/#findComment-328816 Share on other sites More sharing options...
michaellunsford Posted August 20, 2007 Author Share Posted August 20, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/65735-solved-too-many-files/#findComment-328854 Share on other sites More sharing options...
Daniel0 Posted August 20, 2007 Share Posted August 20, 2007 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). Quote Link to comment https://forums.phpfreaks.com/topic/65735-solved-too-many-files/#findComment-328973 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.