marcosrg93 / tvrename

Automatically exported from code.google.com/p/tvrename
Other
0 stars 0 forks source link

Remove empty folders left behind after moving files #33

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
optionally remove empty folders left behind after moving files.

"Empty" may mean "less than xxx bytes of files" or "only NFO, TXT files".

Original issue reported on code.google.com by tvren...@tvrename.com on 10 Sep 2009 at 12:38

GoogleCodeExporter commented 9 years ago
Suggestion on how to implement:

In general, you need to add a preference for whether or not to enable this 
feature, and for the various possible options/variations.  While some moves may 
leave a folder empty, others may leave behind NFO or TXT files, and maybe a 
"Sample" folder.  The idea is to give the user the option to say how empty the 
folder should be, before it is deleted.  Maybe also let the user optionally set 
a limit on the maximum size of files to delete, as a final safety check.

Then, whenever a file is moved from one folder to another, see if the checks 
are enabled and, if they are, check the criteria for "empty" are met, then 
delete the folder and its contents.

Maybe also have a "move to recycle bin" option, too, so the user can retrieve 
their files if it gets it wrong.

Relevant coding things:
- Add new variables to the "TVSettings" class in "Settings/Settings.cs", along 
with the code to load/save them in the constructor and "WriteXML" function.
- Add new user-interface items (and code) to the "Preferences.cs" dialog.  
Maybe at the bottom of the "General" tab, or make a new tab for it.
- In ActionCopyMoveRename.cs, the class of the same name represents a 
particular "Action" to do (i.e. something row shown on the "Scan" tab).  This 
particular class has variables that say what to do (copy/move/rename), along 
with the source and destination filenames.  Of these, only a "move" will leave 
an empty folder.  So, after the work is done (just before the "Go" function 
returns), if the "Delete empty folders" setting is on, call a function that 
does the checks (described above), and deletes the source folder if it is 
empty.  You can set the "Error" and "ErrorText" variables if something goes 
wrong during the delete.
- If the user sets a maximum size limit, you'll have to recursively search the 
folders adding the sizes of everything up.  If you do the delete, then 
"Directory.Delete(folder, true)" will do it recursively.
- When doing the checks, try to order them so the quicker ones are done first, 
in particular doing the recursive size-of-contents count last (and only if it 
is enabled!), as it will be the slowest.

Link: Recycling a file or folder: 
http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/f2411a7f-34b6-4f30
-a25f-9d456fe1c47b/

Original comment by tvren...@tvrename.com on 11 May 2011 at 1:18