Page 1 of 1

Backup old folder and file name

Posted: 16 Dec 2021, 21:49
by scherzeking
Hi,
is there a way to backup the old folder and file name in the directory, where I renamed files?
I saw that there is an option to export "xattr". But in there I do only see the old file name, not the original folder name.

Re: Backup old folder and file name

Posted: 17 Dec 2021, 01:09
by rednoah

Re: Backup old folder and file name

Posted: 17 Dec 2021, 15:53
by scherzeking
Thank you. After some searching and testing I came up with this batch script:

Code: Select all

@echo off
filebot -rename -r %1 --format "{n}/{'Season '+s}/{s00e00} - {t}" --db TheTVDB --lang German --mode interactive --apply import --action TEST --output "Z:\Output"
filebot -script fn:history > "Z:\Output\renamed.txt"
pause
Where I can drop a folder to the batch. Then the files/folder will get renamed. However: Is it possible to also get the {n} parameter as a value from the current renamed files to write the history in that folder? e.g. "Z:\Output\Movie name\renamed.txt"

Another question: When I clear the history with -clear-history I will not be able to revert the files right? I saw that there is an export function in the GUI for the history, but that is a xml file. Is it possible to export this as well in CLI?

Re: Backup old folder and file name

Posted: 17 Dec 2021, 16:56
by rednoah
1.
You could do something like this:

Code: Select all

filebot -mediainfo -r /input --format "{n} | {f} | {historic.f}"

:arrow: The -exec option seems more appropriate for your specific use case though. Have filebot call your custom script with various arguments, then have your custom script write something to somewhere based on those arguments.

Code: Select all

-exec /path/to/script.sh {f} {historic.f}
:arrow: Perhaps something like this, after Windows CMD gymnastics:

Code: Select all

filebot ... -exec cmd /c "X:/write-history.cmd" {f} {historic.f}

Code: Select all

@echo off
echo "%2" >> "%1.renamed.txt"

2.
The history.xml file in the FileBot application data folder is the source of truth. Everything else is just an export thereof. -clear-history will delete that file. You can you can import / export the original file with the copy command.

Re: Backup old folder and file name

Posted: 22 Dec 2021, 01:02
by scherzeking
Hello rednoah, thank you for the reply.
After your hints, I was reading more in the docs on how I was able to achieve this. I came up with a batch script (Here you see it for TV-Shows). And it is finally working now, after many trial and errors.

Code: Select all

@echo off
SET input=%1
SET output="Z:\Output Serien"
filebot -rename -r %input% --format "{n}/{'Season '+s}/{s00e00} - {t}" --db TheTVDB --lang German --mode interactive --apply import --output %output% -exec "Z:\Input Serien\ZZZrenameSkript.bat" %output% "{n}" "{'Season '+s}" "{s00e00}" %input% "{original}"

Code: Select all

@echo off
SET output=%1
SET output2=%output:~0,-1%\
SET name=%2
SET nameNEW=%name:~1,-1%\
SET staffel=%3
SET staffelNEW=%staffel:~1,-1%\
SET episode=%4-
SET origOrdner=%5
SET origOrdnerNEW=%origOrdner:~17,-1%
SET OrigName=%6
SET outputOrdner=%output2%%nameNEW%%staffelNEW%"
SET outputOrdner2=%output2%%nameNEW%%staffelNEW%
SET outputEpisode=%outputOrdner2%%origOrdnerNEW%\%episode%%OrigName%
if not exist %outputOrdner2%%origOrdnerNEW%" mkdir %outputOrdner2%%origOrdnerNEW%"
type NUL > %outputEpisode%.txt"
I know it's messy, but this was driving me crazy, and I'm happy, that it finally works now.
The script will start, when I move a TV-Show folder over the first batch file. The setup for movies is similar.
Please let me know what you think. Maybe there is some room for improvement.

Edit: The structure I get from this looks like this:
From

Code: Select all

Z:\Input Serien\Spice.and.Wolf.German.AC3.DL.1080p....
To this:

Code: Select all

Z:\Output Serien\Spice and Wolf (2008)\Season 1\S01E01 - Die Wölfin und das edle Gewand.mkv
with the old/original folder name and the original file names as 0kb text files Inside:

Code: Select all

Z:\Output Serien\Spice and Wolf (2008)\Season 1\Spice.and.Wolf.German.AC3.DL.1080p....\S01E01-Spice.and.Wolf.E01v2.German.AC3.DL.1080p...txt
You have to make sure, that you have the same path length. Otherwise the script will brake.
Also I can copy the current history to the new path. But for now I will leave it out.

Code: Select all

xcopy "C:\Users\...\AppData\Roaming\FileBot\history.xml" %outputOrdner% /Y