delete unused folders??

stewood

11-04-2009 03:09:49

I am not sure how feasable this is, but it is my last "manual" process in my TV orginizing.

Some files end up downloading into folders. TVRename does a great job of getting the files to where they should be, but I am left with empty folders.

Can you think of a logical way to implement a folder deleation option that would clean up the folders without doing something dangerous (i.e. removing folders that people might want)?

-Stewood

Flain

15-04-2009 13:04:17

Sounds good, i second this request!You CAN use other 3rd party apps to do a clean up like this (find all folders with 0 files and delete) but including the feature in tvrename would be awesome :)

stewood

16-04-2009 23:36:54

Very True.

I found this script on the interwebs and moded it to run as part of my post processing.

-Stewood


'*******************************************************************************
'* File: EmptyFolders.vbs
'* Author:
'* Purpose: This script will delete empty folders that are older than 2 days from a
'* specified directory and write the list to a text file.
'* Version: 1.01 (May 09, 2008)
'* Technology: VBScript
'* Requirements: Windows 2000 or later
'*******************************************************************************
'On Error Resume Next

Option Explicit

Dim arrFolders()
Dim objFSO
Dim objFile
Dim intSize
Dim intDaysOld
Dim objSubfolder
Dim strFolderName
Dim strFolder
Dim i
Dim strDirPath
Dim colNamedArguments
Dim strLogDirPath

Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colNamedArguments = WScript.Arguments.Named

If Not colNamedArguments.Exists("Path") Then 'Checks for Path argument
Wscript.Echo "Usage: /Path:<dirpath> and /LogPath:<logdirpath> required."
Wscript.Quit
Else
strDirPath = colNamedArguments.Item("Path")
End If

If Not colNamedArguments.Exists("LogPath") Then 'Checks for LogPath argument
Wscript.Echo "Usage: /Path:<dirpath> and /LogPath:<logdirpath> required."
Wscript.Quit
Else
strLogDirPath = colNamedArguments.Item("LogPath")
Wscript.Echo "Directory Path: " & strDirPath
Wscript.Echo "Log Directory Path: " & strLogDirPath
End If

If objFSO.FolderExists(strDirPath) Then 'Checks if directory exists
Else
Wscript.Echo "Directory does not exist."
Wscript.Quit
End If

Set objFile = objFSO.OpenTextFile(strLogDirPath, ForWriting, True)

intSize = 0 'Initial size of array
intDaysOld = 2 'Folder age in days

ShowSubFolders objFSO.GetFolder(strDirPath) 'Calls subroutine

Sub ShowSubFolders(Folder)
For Each objSubfolder In Folder.SubFolders
If objSubfolder.Size = 0 And _
objSubfolder.DateLastModified < (Date() - intDaysOld) Then 'Checks age of folders
strFolderName = objSubfolder.Path
ReDim Preserve arrFolders(intSize) 'Adjusts dynamic array size
arrFolders(intsize) = strFolderName
intSize = intSize + 1 'Increases array list for each item

Wscript.Echo "Path: " & objSubfolder.Path 'Displays path of empty folder
Wscript.Echo "Size: " & objSubfolder.Size 'Displays size of empty folder
End If
ShowSubFolders objSubfolder 'Loops subroutine
Next
End Sub

If intSize > 0 Then 'Checks size of array
For i = Ubound(arrFolders) To 0 Step -1 'Reverses the array
strFolder = arrFolders(i)
objFile.WriteLine strFolder & " " & Now 'Writes array list, date and time to log
objFSO.DeleteFolder(strFolder) 'Deletes subfolders, uncomment to delete
Next
Else
objFile.WriteLine "No folders were found. " & Now 'Writes output to log
End If

objFile.Close

sstteevvee

19-04-2009 18:03:40

Tidying up empty folders after moving files is already on my list. I plan to make it so you can optionally define "empty" as something like "with just nfo, sub, sfv and sample files left behind."