nuhll

Is this script problematic? remove empty directorys

5 posts in this topic Last Reply

Recommended Posts

Posted (edited)

I want to remove all directorys after /mnt/user/1/this if its empty

 

so i use 

 

find /mnt/user/downloads/completed/this/ -type d -empty -exec rmdir {} \;
mkdir /mnt/user/downloads/completed/this
 

in user scripts, i mkdir, bc it deletes "this" also, but should only remove the dirs AFTER "this".

 

It works, but it is problematic for unraid in someway? (i dont think so)

 

Or is there a way to first only delete any folders AFTER "this" and keep "this", even if its empty?

 


BTW.  "this" is a user share

Edited by nuhll

Share this post


Link to post
Posted (edited)

Anyone know if its problematic that i remove a user share directory and recreate it every hour?

(or know a way i can edit this script so it doesnt delete this

Edited by nuhll

Share this post


Link to post

Hmm, i "fixxed" it by touching a temp file before running the "delete empty folders script" in the folders i want to keep. 

Share this post


Link to post
2 hours ago, nuhll said:

Hmm, i "fixxed" it by touching a temp file before running the "delete empty folders script" in the folders i want to keep. 

 

This is a quite common trick in use. Same as checkout of source code from repositories often may check out place-holder files just to auto-create required directories.

 

You can also consider doing find /mnt/user/downloads/completed/this/* to make find run on the entries in the this/ directory instead of running on this/ itself.

 

  • Like 1

Share this post


Link to post

As always, thanks! So i know im not doing something stupid, again. :)

Share this post


Link to post

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


Copyright © 2005-2018 Lime Technology, Inc.
unRAID® is a registered trademark of Lime Technology, Inc.