Jump to content

Module: Clean empty directories from /site/assets/files/


ryan
 Share

Recommended Posts

This module goes through all of your /site/assets/files/ directories and removes those that have no files in them.

http://modules.proce...ean-empty-dirs/

Pages with file/image fields require a directory, so you should expect that some of the removed directories will be re-created by these pages.

As of today, ProcessWire no longer creates directories for all pages, so this module is mostly useful to existing sites rather than future sites.

I am listing it as "alpha" just because I've only tested on my own sites. Once I get confirmation from others that it also worked well for them, I will change its status to stable. Until it is considered stable, I suggest only running it in dev/test environments (not that it does anything dangerous, but just a good practice).

  • Like 6
Link to comment
Share on other sites

3,819 folders reduced to 1,128 - muuuuch better :)

I'm sure some will re-surface as my files section template allows either an external URL or a file as well as an optional screenshot, but I guess they're not updated often past the initial page creation.

As you say in the other thread ryan, this could well be run every so often to tidy things up. I guess a nice addition could be to tie it in with the LazyCron module to make that automated on a weekly/monthly basis.

Link to comment
Share on other sites

As you say in the other thread ryan, this could well be run every so often to tidy things up. I guess a nice addition could be to tie it in with the LazyCron module to make that automated on a weekly/monthly basis.

If you are running the latest commit of ProcessWire, there's not really any reason to run this module more than once. And when you start a new site today or in the future (using the latest version of PW), then there's no need to run this module ever. I think this module would only be worthwhile as a recurring maintenance task if you are running an older version of ProcessWire. The only other situation I can think of is if you had files fields on some pages and later removed the files fields, the directories would still remain as long as the page existed, and this module would remove them.

Link to comment
Share on other sites

  • 8 months later...

Hi Ryan,

I'm making progress on my first PW site. I'm very pleased, so far! I'm replicating a structure I had done in MODX, and it's an interesting process.

On this issue of "Pages with file/image fields require a directory" -- what about the scenario of a site with many thousands of articles, where the article pages have the image field, but perhaps only 50% of the articles have actual images?

I would think that it would be much, much better to only create a directory when an image is attached to the page, and when it's deleted, then remove the image and the directory. It seems inefficient to have thousands of empty directories.

Also, wouldn't that add to the max number of inodes, perhaps causing an issue?

Thanks!

Peter

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...