Clean function not removing empty folders

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
valiantslack
Posts: 18
Joined: 17 Jun 2019, 17:10

Clean function not removing empty folders

Post by valiantslack »

For some time now the clean=y function has not been working for me. I believe this started when I had to update my script to use the ut_dir parameter.
The log file doesn't show the empty folders that it used to delete. One of the folders does have a hidden file that is 1MB, though I'm sure it used to delete these as well.

Groovy: Select all

-script
fn:amc
-non-strict
--output
N:/
--action
move
--conflict
skip
--log-file
N:/Media/#Unprocessed/AMC/amc.log
--def
clean=y
minLengthMS=0
ignore=AMC|Extracted|Placeholder
pushover=******
seriesDB=TheMovieDB::TV
movieFormat=N:/Media/Movies/{ any{ certification ==~ /G|PG/ ? 'Family' : 'Adults' }{ 'Adults' } }/{ ~plex ** { ' ' + [vf] + [certification] } }{ [group] }
seriesFormat=N:/Media/TV Shows/{ any{ certification ==~ /G|TV-G|TV-Y|TV-Y7/ ? 'Kids TV' : 'Adults' }{ 'Adults'} }/{plex.tail}
excludeList=N:/Media/#Unprocessed/AMC/amcexclude.txt
ut_dir=N:/Media/#Unprocessed
Log file

Console Output: Select all

Run script [fn:amc] at [Mon Oct 13 00:00:03 MDT 2025]
Parameter: clean = y
Parameter: minLengthMS = 0
Parameter: ignore = AMC|Extracted|Placeholder
Parameter: pushover = *****
Parameter: seriesDB = TheMovieDB::TV
Parameter: movieFormat = N:/Media/Movies/{ any{ certification ==~ /G|PG/ ? 'Family' : 'Adults' }{ 'Adults' } }/{ ~plex ** { ' ' + [vf] + [certification] } }{ [group] }
Parameter: seriesFormat = N:/Media/TV Shows/{ any{ certification ==~ /G|TV-G|TV-Y|TV-Y7/ ? 'Kids TV' : 'Adults' }{ 'Adults'} }/{plex.tail}
Parameter: excludeList = N:/Media/#Unprocessed/AMC/amcexclude.txt
Parameter: ut_dir = N:/Media/#Unprocessed
Invalid usage: input folder [N:/Media/#Unprocessed] must not start with output folder [N:\]
Invalid usage: --def ut_dir and --def ut_kind must be specified in tandem
Use excludes: N:\Media\#Unprocessed\AMC\amcexclude.txt (4)
Ignore hidden: N:\Media\#Unprocessed\.sync
Ignore pattern: N:\Media\#Unprocessed\AMC
Ignore pattern: N:\Media\#Unprocessed\Duplicate Show Override - AMC.ps1
Ignore pattern: N:\Media\#Unprocessed\Extracted
Ignore pattern: N:\Media\#Unprocessed\Placeholder.txt
Input: N:\Media\#Unprocessed\60.Minutes.S58E03.1080p.WEB.h264-BAE.mkv
Group files by movie or series
Group: {Series=60 Minutes (1968)} => [60.Minutes.S58E03.1080p.WEB.h264-BAE.mkv]
Rename episodes using [TheMovieDB] with [Airdate Order]
Lookup via [60 Minutes] [60 Minutes]
Fetching episode data for [60 Minutes]
* 60 Minutes [651] | 978 episodes | 1x01-06 .. 2x01 .. 3x01 .. 4x01 .. 5x01 .. 6x01 .. 7x33 .. 16x04 .. 22x27 .. 24x32x52 .. 25x43 .. 26x44 .. 27x42 .. 28x02 .. 30x31 .. 31x28 .. 33x06x09x33 .. 34x01-12 .. 35x01x07x37 .. 36x01x02x03x04x05x06x07x08x09x36 .. 37x01x02x03x04x05x12x21 .. 38x01x21x29x37x39 .. 39x01x27x42 .. 40x01-52 .. 41x01-50 .. 42x01x02x03x04x05x06x07x08x09x10x11x12x14x15x16x17x18x19x20x21x22x24x25x26x27x31x32x33x34x35x36x37x38x39x40x41x42x43x44x45x46x47x48x49x50x51 .. 43x01x02x03x04x05x06x07x08x09x10x11x12x13x14x15x16x17x18x19x20x21x22x24x25x26x27x28x29x30x31x32x33x34x35x36x37x38x39x40x41x42x43x44x45x46x47x48x49x50x51x52 .. 44x01-53 .. 45x01-48 .. 46x01-51 .. 47x01-52 .. 48x01-55 .. 49x01-23 .. 50x01-55 .. 51x01-51 .. 52x01-50 .. 53x01-51 .. 54x01-56 .. 55x01-54 .. 56x01-55 .. 57x01-57 .. 58x01-03
[MOVE] from [N:\Media\#Unprocessed\60.Minutes.S58E03.1080p.WEB.h264-BAE.mkv] to [N:\Media\TV Shows\Adults\60 Minutes\Season 58\60 Minutes - S58E03 - The China Hack; Booms, Busts and Bubbles; The Road to Damascus.mkv]
Processed 1 file
Sending Pushover notification
Done ヾ(@⌒ー⌒@)ノ
User avatar
rednoah
The Source
Posts: 24306
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Clean function not removing empty folders

Post by rednoah »

1
:idea: Do you really mean to delete your N:/Media/#Unprocessed input folder after each run? What's your reasoning? The typical "run on completed download" use case requires the --def clean=y option to never delete the given input folder. --def ut_dir usage explicitly disables deletion of the root folder. (see amc.groovy#L745)
2

Console Output: Select all

Invalid usage: --def ut_dir and --def ut_kind must be specified in tandem
:idea: If you're using --def ut_dir then you must also specify --def ut_kind=multi. Since usage is incorrect, the cleaner script is never called. That's why you don't see Keep N:/Media/#Unprocessed (root folder) in the console output. (see amc.groovy#L741 and cleaner.groovy#L89)
3
:!: Note that --def clean=y does delete *.log, *.txt, *.ps1, etc files, so you definitely don't want to put your persistent log files into a folder that you expect to be deleted after each run:

Code: Select all

N:/Media/#Unprocessed/AMC/amc.log
N:/Media/#Unprocessed/AMC/amcexclude.txt
4

Console Output: Select all

Invalid usage: input folder [N:/Media/#Unprocessed] must not start with output folder [N:\]
:idea: I recommend separating input / output folder clearly and not mixing everything together in the same media folder:

Shell: Select all

--output "N:/Media" --def ut_dir="N:/Downloads/#Unprocessed" --def ut_kind="multi"


EDIT
:idea: Note that you can run The Cleaner script independently of the amc script when needed (e.g. right after the amc script call) and with custom options as needed:

Shell: Select all

filebot -script fn:cleaner "N:/Downloads/#Unprocessed" --def root=y


EDIT 2
Commit 29f901c: Assume --def ut_kind=multi if --def ut_dir is specified but --def ut_kind and --def ut_file are both omitted
:idea: Please read the FAQ and How to Request Help.
valiantslack
Posts: 18
Joined: 17 Jun 2019, 17:10

Re: Clean function not removing empty folders

Post by valiantslack »

No, my intention is to delete any empty season/movie folders after processing that are in the input folder. Prior to having to use --def ut_dir this was the case.

I added --def ut_kind=multi though I couldn't find what this does exactly.
Note that --def clean=y does delete *.log, *.txt, *.ps1, etc files, so you definitely don't want to put your persistent log files into a folder that you expect to be deleted after each run:
Is this new? When --def clean=y used to work it never deleted the above files, but I think that is because I have --def ignore=AMC|Extracted|Placeholder in place.
I recommend separating input / output folder clearly and not mixing everything together in the same media folder:
I have looked into this before and requires me to re-structure multiple automations related to my media server. However, it's not impossible.

I tested the script after adding --def ut_kind=multi and it deleted an empty test folder. However, running it again with a new test folder I created and it doesn't seem to work. Is this because it didn't process any files?

Console Output: Select all

Run script [fn:amc] at [Tue Oct 14 08:43:09 MDT 2025]
Parameter: clean = y
Parameter: ignore = AMC|Extracted|Placeholder
Parameter: pushover = *****
Parameter: seriesDB = TheMovieDB::TV
Parameter: movieFormat = N:/Media/Movies/{ any{ certification ==~ /G|PG/ ? 'Family' : 'Adults' }{ 'Adults' } }/{ ~plex ** { ' ' + [vf] + [certification] } }{ [group] }
Parameter: seriesFormat = N:/Media/TV Shows/{ any{ certification ==~ /G|TV-G|TV-Y|TV-Y7/ ? 'Kids TV' : 'Adults' }{ 'Adults'} }/{plex.tail}
Parameter: ut_dir = N:/Media/#Unprocessed
Parameter: ut_kind = multi
Invalid usage: input folder [N:/Media/#Unprocessed] must not start with output folder [N:\]
Ignore hidden: N:\Media\#Unprocessed\.sync
Ignore pattern: N:\Media\#Unprocessed\AMC
Ignore pattern: N:\Media\#Unprocessed\Duplicate Show Override - AMC.ps1
Ignore pattern: N:\Media\#Unprocessed\Extracted
Ignore pattern: N:\Media\#Unprocessed\Placeholder.txt
Ignore hidden: N:\Media\#Unprocessed\Solar.Opposites.S06.1080p.DSNP.WEB-DL.DDP5.1.H.264-NTb\.Solar.Opposites.S06E01.The.Unfortunate.Destruction.of.the.Diamond.Making.Machine.1080p.DSNP.WEB-DL.DDP5.1.H.264-NTb.mkv.9gA9GY
Input: N:\Media\#Unprocessed\Only.Murders.in.the.Building.S05E08.Cuckoo.Chicks.1080p.DSNP.WEB-DL.DDP5.1.H.264-NTb.mkv
Group files by movie or series
Group: {Series=Only Murders in the Building (2021)} => [Only.Murders.in.the.Building.S05E08.Cuckoo.Chicks.1080p.DSNP.WEB-DL.DDP5.1.H.264-NTb.mkv]
Rename episodes using [TheMovieDB] with [Airdate Order]
Lookup via [Only Murders in the Building] [Only Murders in the Building]
Fetching episode data for [Only Murders in the Building]
* Only Murders in the Building [107113] | 50 episodes | 1x01-10 .. 2x01-10 .. 3x01-10 .. 4x01-10 .. 5x01-10
[REPLACE] Delete [N:\Media\TV Shows\Adults\Only Murders in the Building\Season 05\Only Murders in the Building - S05E08 - Cuckoo Chicks.mkv]
[MOVE] from [N:\Media\#Unprocessed\Only.Murders.in.the.Building.S05E08.Cuckoo.Chicks.1080p.DSNP.WEB-DL.DDP5.1.H.264-NTb.mkv] to [N:\Media\TV Shows\Adults\Only Murders in the Building\Season 05\Only Murders in the Building - S05E08 - Cuckoo Chicks.mkv]
Processed 1 file
Sending Pushover notification
Clean clutter files and empty folders
Keep N:\Media\#Unprocessed\AMC\amc.log (not clutter)
Keep N:\Media\#Unprocessed\AMC\amcexclude.txt (not clutter)
Keep N:\Media\#Unprocessed\AMC\context.txt (not clutter)
Keep N:\Media\#Unprocessed\AMC\context_duplicate.txt (not clutter)
Keep N:\Media\#Unprocessed\AMC\Filebot.ps1 (not clutter)
Keep N:\Media\#Unprocessed\AMC\Filebot - Original - Pre-context file.ps1 (not clutter)
Keep N:\Media\#Unprocessed\AMC\Test AMC script.txt (not clutter)
Keep N:\Media\#Unprocessed\Extracted\Placeholder.txt (not clutter)
Keep N:\Media\#Unprocessed\Duplicate Show Override - AMC.ps1 (not clutter)
Keep N:\Media\#Unprocessed\Placeholder.txt (not clutter)
Delete N:\Media\#Unprocessed\test
Keep N:\Media\#Unprocessed\Solar.Opposites.S06.1080p.DSNP.WEB-DL.DDP5.1.H.264-NTb [.Solar.Opposites.S06E01.The.Unfortunate.Destruction.of.the.Diamond.Making.Machine.1080p.DSNP.WEB-DL.DDP5.1.H.264-NTb.mkv.9gA9GY] (not empty)
Keep N:\Media\#Unprocessed\Extracted [Placeholder.txt] (not empty)
Keep N:\Media\#Unprocessed\AMC [amc.log, amcexclude.txt, context.txt, context_duplicate.txt, Filebot.ps1, Filebot - Original - Pre-context file.ps1, Test AMC script.txt] (not empty)
Keep N:\Media\#Unprocessed [.sync, AMC, Duplicate Show Override - AMC.ps1, Extracted, Placeholder.txt, Solar.Opposites.S06.1080p.DSNP.WEB-DL.DDP5.1.H.264-NTb] (not empty)
Done ヾ(@⌒ー⌒@)ノ
User avatar
rednoah
The Source
Posts: 24306
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Clean function not removing empty folders

Post by rednoah »

The cleaner script is now running as expected:

Console Output: Select all

Clean clutter files and empty folders
Keep N:\Media\#Unprocessed\AMC\amc.log (not clutter)
Keep N:\Media\#Unprocessed\AMC\amcexclude.txt (not clutter)
Keep N:\Media\#Unprocessed\AMC\context.txt (not clutter)
Keep N:\Media\#Unprocessed\AMC\context_duplicate.txt (not clutter)
Keep N:\Media\#Unprocessed\AMC\Filebot.ps1 (not clutter)
Keep N:\Media\#Unprocessed\AMC\Filebot - Original - Pre-context file.ps1 (not clutter)
Keep N:\Media\#Unprocessed\AMC\Test AMC script.txt (not clutter)
Keep N:\Media\#Unprocessed\Extracted\Placeholder.txt (not clutter)
Keep N:\Media\#Unprocessed\Duplicate Show Override - AMC.ps1 (not clutter)
Keep N:\Media\#Unprocessed\Placeholder.txt (not clutter)
Delete N:\Media\#Unprocessed\test
Keep N:\Media\#Unprocessed\Solar.Opposites.S06.1080p.DSNP.WEB-DL.DDP5.1.H.264-NTb [.Solar.Opposites.S06E01.The.Unfortunate.Destruction.of.the.Diamond.Making.Machine.1080p.DSNP.WEB-DL.DDP5.1.H.264-NTb.mkv.9gA9GY] (not empty)
Keep N:\Media\#Unprocessed\Extracted [Placeholder.txt] (not empty)
Keep N:\Media\#Unprocessed\AMC [amc.log, amcexclude.txt, context.txt, context_duplicate.txt, Filebot.ps1, Filebot - Original - Pre-context file.ps1, Test AMC script.txt] (not empty)
Keep N:\Media\#Unprocessed [.sync, AMC, Duplicate Show Override - AMC.ps1, Extracted, Placeholder.txt, Solar.Opposites.S06.1080p.DSNP.WEB-DL.DDP5.1.H.264-NTb] (not empty)

:idea: N:\Media\#Unprocessed\test was deleted as expected.

:idea: The --def ignore "AMC|Extracted|Placeholder" pattern prevents some files from being deleted. The in-progress download *.9gA9GY is not deleted because it's got a strange extension and the cleaner won't touch unknown extensions / large files / etc.

:idea: The amc script indeed does not run the cleaner script if no files were processed. It would print Finished without processing any files and exit. It seems everything is back to normal. The missing --def ut_kind=multi parameter caused the cleaner script to not run. We'll account for that in future revisions of the amc script.
:idea: Please read the FAQ and How to Request Help.
valiantslack
Posts: 18
Joined: 17 Jun 2019, 17:10

Re: Clean function not removing empty folders

Post by valiantslack »

Got it, thanks for the assistance!
smithjohns
Posts: 1
Joined: 11 Nov 2025, 07:57

Re: Clean function not removing empty folders

Post by smithjohns »

thanks a lot
Post Reply