Add <genre> info to directoryname and transfer all files form old dir to new dir with extended name
Moderators: Hacker, petermad, Stefan2, white
Add <genre> info to directoryname and transfer all files form old dir to new dir with extended name
Hi, so here's my problem:
have a non-small collection of audiobooks, normally sorted by directory named <author-ABookname-Year>. now I want to add the content of the genre identifier from the mp3 files inside the directory to the directory name. problem is now, by using the TC renametool, only the mp3 files will be transferred to the new directory with extended name, all other files will remain in the old dir and have to be transfered manually, so a scripted solution can be more effective, but I'm not able to do this... maybe s.o. you can help me out...
TIA
Mike
have a non-small collection of audiobooks, normally sorted by directory named <author-ABookname-Year>. now I want to add the content of the genre identifier from the mp3 files inside the directory to the directory name. problem is now, by using the TC renametool, only the mp3 files will be transferred to the new directory with extended name, all other files will remain in the old dir and have to be transfered manually, so a scripted solution can be more effective, but I'm not able to do this... maybe s.o. you can help me out...
TIA
Mike
#664 Personal license
Re: Add <genre> info to directoryname and transfer all files form old dir to new dir with extended name
Can you be more precise about your issue and the remaining files ?
Can you give details abut what dyou have in initial folder <author-ABookname-Year> and what do you want in final folder(s) ?
if you have a naming scheme that helps to capture non mp3 files from mp3 files, that should be doable with a batch script or with TCBL.
Can you give details abut what dyou have in initial folder <author-ABookname-Year> and what do you want in final folder(s) ?
if you have a naming scheme that helps to capture non mp3 files from mp3 files, that should be doable with a batch script or with TCBL.
Re: Add <genre> info to directoryname and transfer all files form old dir to new dir with extended name
You can do so by creating a button on one of your button bars.
Selecting an audiobook folder - for example "Author-ABookname-Year" and clicking this button will rename the folder to "Genre - Author-ABookname-Year"
The genre is detected by analyzing the first MP3/FLAC file in that folder.
Illegal filename characters in the genre - like * \ / ? , etc - will be replaced by an underscore ( _ ).
Here is how to accomplish that:
Selecting an audiobook folder - for example "Author-ABookname-Year" and clicking this button will rename the folder to "Genre - Author-ABookname-Year"
The genre is detected by analyzing the first MP3/FLAC file in that folder.
Illegal filename characters in the genre - like * \ / ? , etc - will be replaced by an underscore ( _ ).
Here is how to accomplish that:
- Download the Windows executable of EXIFTOOL (currently exiftool-12.09.zip) from the official website
- Unzip it to a folder of your choice
- Rename exiftool(-k).exe to exiftool.exe
- Copy the following buttoncode to the clipboard:
ButtonCode
Code: Select all
TOTALCMD#BAR#DATA powershell.exe -noprofile -nologo -NoExit -Command & "{ $GENRE = (& "T:\exiftool-11.85\exiftool.exe" -Genre -s3 ('"' + '%N'.trim('"') + '\' + (gci ('%N'.trim('"') + '\*') -include *.flac,*.mp3)[0].Name +'"') ) -creplace( '[\\/:\*`"\?\<\>\|]' , '_' ) ; If (test-Path variable::Genre) { ren '%N' ($GENRE + ' - ' + '%N'.trim('"')) -whatif } }" powershell.exe Add Genre to Foldername -1
- Paste the buttoncode in a text editor, for example Notepad.
In the line
-noprofile -nologo -NoExit -Command & "{ $GENRE = (& "T:\exiftool-11.85\exiftool.exe" -Genre -s3 ('"' + '%N'.trim('"') + '\' + (gci ('%N'.trim('"') + '\*') -include *.flac,*.mp3)[0].Name +'"') ) -creplace( '[\\/:\*`"\?\<\>\|]' , '_' ) ; If (test-Path variable::Genre) { ren '%N' ($GENRE + ' - ' + '%N'.trim('"')) -whatif } }"
replace the BLUE part with the actual location of your exiftool.exe (don't forget the "" ) - Copy the entire text to the clipboard
- In Total Commander, right-click an empty part of your buttonbar and select Paste
A new button will appear with the PowerShell icon (you can change this later on, if you wish) - Select one of your audiobook folders
- Click on the Add Genre to foldername button.
Note: in the current configuration this will only do a SIMULATION by showing you how the folder *would be* renamed - Close the rename simulation window.
- Repeat these steps for some of your other audiobook folders to see if it behaves as expected.
- If all is OK, you can edit the buttoncode and remove the RED parts ( -NoExit and -whatif )
From that point on, it will do the actual renaming.
To edit the button code:- Right-click the button
- Click Change
- Post your results here
Re: Add <genre> info to directoryname and transfer all files form old dir to new dir with extended name
This is an (international) continuation of this thread on the German forum.
That thread has a bit more information (which I used).
Re: Add <genre> info to directoryname and transfer all files form old dir to new dir with extended name
Hi,
thats really impressive, thank you very much!! up to now I havn't found a dir with an empty genre-id.
I've tried to analyze what these powershell cmdline params do, to achieve that the genre-id will become not a name-addon, but a path, so that the abook is transferred automaticly to a dir that contains all Fantasy and/or other abooks-classes. and the final question is how to make this procedure to go rekursively throughout the whole dir-tree.
I fear it may be seen a bit too offensive, but if there is a firendly guy that can help me to this point, why not asking him to make this procedure at least a perkekt one
???
so it would be very gentil if you could spend an additional time to round this up to my special requirements, maybe there are others that may use it with the same appreciation as I will do...
kind regs and TIA
Mike
thats really impressive, thank you very much!! up to now I havn't found a dir with an empty genre-id.
I've tried to analyze what these powershell cmdline params do, to achieve that the genre-id will become not a name-addon, but a path, so that the abook is transferred automaticly to a dir that contains all Fantasy and/or other abooks-classes. and the final question is how to make this procedure to go rekursively throughout the whole dir-tree.
I fear it may be seen a bit too offensive, but if there is a firendly guy that can help me to this point, why not asking him to make this procedure at least a perkekt one

so it would be very gentil if you could spend an additional time to round this up to my special requirements, maybe there are others that may use it with the same appreciation as I will do...
kind regs and TIA
Mike
NotNull wrote: 2020-11-07, 15:05 UTC You can do so by creating a button on one of your button bars.
Selecting an audiobook folder - for example "Author-ABookname-Year" and clicking this button will rename the folder to "Genre - Author-ABookname-Year"
The genre is detected by analyzing the first MP3/FLAC file in that folder.
Illegal filename characters in the genre - like * \ / ? , etc - will be replaced by an underscore ( _ ).
Here is how to accomplish that:
- Download the Windows executable of EXIFTOOL (currently exiftool-12.09.zip) from the official website
- Unzip it to a folder of your choice
- Rename exiftool(-k).exe to exiftool.exe
- Copy the following buttoncode to the clipboard:
ButtonCode
Code: Select all
TOTALCMD#BAR#DATA powershell.exe -noprofile -nologo -NoExit -Command & "{ $GENRE = (& "T:\exiftool-11.85\exiftool.exe" -Genre -s3 ('"' + '%N'.trim('"') + '\' + (gci ('%N'.trim('"') + '\*') -include *.flac,*.mp3)[0].Name +'"') ) -creplace( '[\\/:\*`"\?\<\>\|]' , '_' ) ; If (test-Path variable::Genre) { ren '%N' ($GENRE + ' - ' + '%N'.trim('"')) -whatif } }" powershell.exe Add Genre to Foldername -1
- Paste the buttoncode in a text editor, for example Notepad.
In the line
-noprofile -nologo -NoExit -Command & "{ $GENRE = (& "T:\exiftool-11.85\exiftool.exe" -Genre -s3 ('"' + '%N'.trim('"') + '\' + (gci ('%N'.trim('"') + '\*') -include *.flac,*.mp3)[0].Name +'"') ) -creplace( '[\\/:\*`"\?\<\>\|]' , '_' ) ; If (test-Path variable::Genre) { ren '%N' ($GENRE + ' - ' + '%N'.trim('"')) -whatif } }"
replace the BLUE part with the actual location of your exiftool.exe (don't forget the "" )- Copy the entire text to the clipboard
- In Total Commander, right-click an empty part of your buttonbar and select Paste
A new button will appear with the PowerShell icon (you can change this later on, if you wish)- Select one of your audiobook folders
- Click on the Add Genre to foldername button.
Note: in the current configuration this will only do a SIMULATION by showing you how the folder *would be* renamed- Close the rename simulation window.
- Repeat these steps for some of your other audiobook folders to see if it behaves as expected.
- If all is OK, you can edit the buttoncode and remove the RED parts ( -NoExit and -whatif )
From that point on, it will do the actual renaming.
To edit the button code:
- Right-click the button
- Click Change
- Post your results here
#664 Personal license
Re: Add <genre> info to directoryname and transfer all files form old dir to new dir with extended name
Folders containing mp3/flac files without Genre should be skipped. [1]
Why didn't you ask so in the first place? Now it is double the work as this will probably become a non-TC solution.vSalisch wrote: 2020-11-08, 11:14 UTC to achieve that the genre-id will become not a name-addon, but a path, so that the abook is transferred automaticly to a dir that contains all Fantasy and/or other abooks-classes.
What do you mean by that?vSalisch wrote: 2020-11-08, 11:14 UTC and the final question is how to make this procedure to go rekursively throughout the whole dir-tree.
Are all your audiobook folders in "X:\some folder\" like this:
"X:\some folder\Author-BooknameA-YearA"
"X:\some folder\Author-BooknameB-YearB"
or is the structure more like:
"X:\some folder\Author-BooknameA-YearA"
"X:\some folder\another folder\and yet another folder\"Author-BooknameB-YearB"
(You got yourself a second "wish". Make sure it counts

EDIT:
[1] Just took another look at the code; that statement is not correct.
Replace If (test-Path variable::Genre) with this to make it skip folders without Genre:
If ($Genre)
Re: Add <genre> info to directoryname and transfer all files form old dir to new dir with extended name
hi,
so thanks for the debugging infos on rev 1.0 of your solution.
to be blamed for not coming around in the begining is a bit disturbing to me, cause I would call this "evolution on requirements based on achieved effort"
according to the directorystructure is to say that there are two kinds of directories available on my disk:
a) Author - AbookTitel <blank> Year with mp3/flac, txt files underneath
b) Author <blank> #\ ABookTitle1 <blank> Year with mp3/flac, txt files underneath
ABookTitle2 <blank> Year with mp3/flac, txt files underneath
...
ABookTitleN <blank> Year with mp3/flac, txt files underneath
so there is a mixture of those dirNameTypes all over the alphabet. so the wish was that dirs without # will be transferred to dirs having the gernreType names within the former dirs-structure of the disk (a) and the dirs with # will be transferred to the apropriate genreType dirs by reproducing the former dir structure (b). this should be done recursively with the whole directory structure already existing on the disk, so in the end the diskdir root should consist only of genreType dirnames with all abooks underneath this structure. so the process should be started once and then ending up when reaching the last dir.
i hope this clearyfies my intention and finally describes the my wish to the good fairy....
Mike
so thanks for the debugging infos on rev 1.0 of your solution.
to be blamed for not coming around in the begining is a bit disturbing to me, cause I would call this "evolution on requirements based on achieved effort"

according to the directorystructure is to say that there are two kinds of directories available on my disk:
a) Author - AbookTitel <blank> Year with mp3/flac, txt files underneath
b) Author <blank> #\ ABookTitle1 <blank> Year with mp3/flac, txt files underneath
ABookTitle2 <blank> Year with mp3/flac, txt files underneath
...
ABookTitleN <blank> Year with mp3/flac, txt files underneath
so there is a mixture of those dirNameTypes all over the alphabet. so the wish was that dirs without # will be transferred to dirs having the gernreType names within the former dirs-structure of the disk (a) and the dirs with # will be transferred to the apropriate genreType dirs by reproducing the former dir structure (b). this should be done recursively with the whole directory structure already existing on the disk, so in the end the diskdir root should consist only of genreType dirnames with all abooks underneath this structure. so the process should be started once and then ending up when reaching the last dir.
i hope this clearyfies my intention and finally describes the my wish to the good fairy....
Mike
#664 Personal license
Re: Add <genre> info to directoryname and transfer all files form old dir to new dir with extended name
So, if I understand correctly, you currently have this structure of folders containing mp3/flac/txt files:
And you want it to become:
Correct ??
No problem, but why not make all folders in the same format:
(option 2)
-or-
(option 3)
Code: Select all
X:\rootdir\AuthorA - BookTitel1 2001
X:\rootdir\AuthorA - BookTitel2 2002
X:\rootdir\AuthorB - BookTitel3 2003
X:\rootdir\AuthorB - BookTitel4 2004
X:\rootdir\AuthorC #\BookTitel5 2005
X:\rootdir\AuthorC #\BookTitel6 2006
X:\rootdir\AuthorD #\BookTitel7 2007
X:\rootdir\AuthorD #\BookTitel8 2007
Code: Select all
X:\rootdir\Science Fiction\AuthorA - BookTitel1 2001
X:\rootdir\Science Fiction\AuthorA - BookTitel2 2002
X:\rootdir\Science Fiction\AuthorB - BookTitel3 2003
X:\rootdir\Science Fiction\AuthorB - BookTitel4 2004
X:\rootdir\Detective\AuthorC #\BookTitel5 2005
X:\rootdir\Detective\AuthorC #\BookTitel6 2006
X:\rootdir\Detective\AuthorD #\BookTitel7 2007
X:\rootdir\Detective\AuthorD #\BookTitel8 2007
Correct ??
No problem, but why not make all folders in the same format:
(option 2)
Code: Select all
X:\rootdir\Science Fiction\AuthorA - BookTitel1 2001
X:\rootdir\Science Fiction\AuthorA - BookTitel2 2002
X:\rootdir\Science Fiction\AuthorB - BookTitel3 2003
X:\rootdir\Science Fiction\AuthorB - BookTitel4 2004
X:\rootdir\Detective\AuthorC - BookTitel5 2005
X:\rootdir\Detective\AuthorC - BookTitel6 2006
X:\rootdir\Detective\AuthorD - BookTitel7 2007
X:\rootdir\Detective\AuthorD - BookTitel8 2007
(option 3)
Code: Select all
X:\rootdir\Science Fiction\AuthorA\BookTitel1 2001
X:\rootdir\Science Fiction\AuthorA\BookTitel2 2002
X:\rootdir\Science Fiction\AuthorB\BookTitel3 2003
X:\rootdir\Science Fiction\AuthorB\BookTitel4 2004
X:\rootdir\Detective\AuthorC\BookTitel5 2005
X:\rootdir\Detective\AuthorC\BookTitel6 2006
X:\rootdir\Detective\AuthorD\BookTitel7 2007
X:\rootdir\Detective\AuthorD\BookTitel8 2007
Re: Add <genre> info to directoryname and transfer all files form old dir to new dir with extended name
Hi, option 1 is the right one. why, because I don't like to have long dirlists beginning with the same author, therefore I decided by the time to choose the # character to signalize that there are several different abooks written by the same author. so its only a question of my way of thinking and organizing (to make a long story short: the egg-head way...)
Mike
Mike
#664 Personal license
Re: Add <genre> info to directoryname and transfer all files form old dir to new dir with extended name
Part 1
This will move all folders that match the pattern ' * - * <4 digits>' - like "A. A. Milne - Winnie-the-Pooh 1926" - to a new Genre folder
Here's how:
PART2 - moving the " Author #" folders - will follow later today.
PART1.ps1
[1]If you have trouble running the PART1.ps1 script:
This will move all folders that match the pattern ' * - * <4 digits>' - like "A. A. Milne - Winnie-the-Pooh 1926" - to a new Genre folder
Here's how:
- Copy EXIFTOOL.exe to X:\rootdir
- Save the following PowerShell code as - for example - PART1.ps1 i that same folder.
- Run PART1.ps1 [1]
- Follow the on-screen intsructions ( = press ENTER for a simulation)
- Check the simulation output
- If all is OK:
- Re-run the PART1.ps1 script
- Type yes (+ ENTER) to actually move these folders in the desired location
- Done (??)
PART2 - moving the " Author #" folders - will follow later today.
PART1.ps1
Code: Select all
cls
$EXECUTE = Read-Host "Press ENTER for simulation. Type YES (+ENTER) to start moving folders ... "
$WHATIF = !( $EXECUTE -eq 'YES')
cd $PSScriptRoot
gci $PSScriptRoot -Directory '* - *' | ? -Property Name -match ' \d{4}$' | % {
"======================================================="
"Handling `"$_`""
$THESEFILES = gci ($_.FullName + '\*') -include *.flac,*.mp3
If (!$THESEFILES) { "No matching files found"; return }
$FIRSTFILE = '"' +$THESEFILES[0].FullName + '"'
$GENRE = (& '.\exiftool.exe' -Genre -s3 $FIRSTFILE ) -creplace( '[\\/:\*`"\?\<\>\|]' , '_' )
"GENRE = `"$GENRE`""
""
If (!$GENRE) { return }
md "$GENRE" -ea Silent -whatif:$WHATIF
Move $_ "$GENRE" -whatif:$WHATIF
}
Read-Host "Press ENTER to finish ... "
- Start CMD.exe
- Run the following commands
Code: Select all
CD /d x:\rootdir powershell.exe -noprofile -ExecutionPolicy bypass .\PART1.ps1
Re: Add <genre> info to directoryname and transfer all files form old dir to new dir with extended name
Part 2
This will move all folders (that end on 4 digits) inside a folder that that match the pattern ' * #' - like "A. A. Milne #" - to a new "Genre\Atrist #" folder.
Here's how:
PART2.ps1
This will move all folders (that end on 4 digits) inside a folder that that match the pattern ' * #' - like "A. A. Milne #" - to a new "Genre\Atrist #" folder.
Here's how:
- Copy EXIFTOOL.exe to X:\rootdir
- Save the following PowerShell code as - for example - PART2.ps1 i that same folder.
- Run PART2.ps1
- Follow the on-screen intsructions ( = press ENTER for a simulation)
- Check the simulation output
- If all is OK:
- Re-run the PART2.ps1 script
- Type yes (+ ENTER) to actually move these folders in the desired location
- When the audiobooks are moved, the 'Author #' folder might end up empty.
If that is the case, you will be asked to confirm the deletion of this empty folder. - Done (??)
PART2.ps1
Code: Select all
cls
$EXECUTE = Read-Host "Press ENTER for simulation. Type YES (+ENTER) to start moving folders ... "
$WHATIF = !( $EXECUTE -eq 'YES')
cd $PSScriptRoot
gci $PSScriptRoot -Directory '*#' | % {
$ARTIST = $_.Name
"$ARTIST"
gci $_ -Directory | ? -Property Name -match ' \d{4}$' | % {
"======================================================="
"Handling `"$_`""
$THESEFILES = gci ($_.FullName + '\*') -include *.flac,*.mp3
If (!$THESEFILES) { "No matching files found"; return }
$FIRSTFILE = '"' +$THESEFILES[0].FullName + '"'
$GENRE = (& '.\exiftool.exe' -Genre -s3 $FIRSTFILE ) -creplace( '[\\/:\*`"\?\<\>\|]' , '_' )
"GENRE = `"$GENRE`""
""
If (!$GENRE) { return }
md "$GENRE\$ARTIST" -ea Silent -whatif:$WHATIF
Move $_.FullName "$GENRE\$ARTIST" -whatif:$WHATIF
}
"======================================================="
if (!$_.GetFileSystemInfos('*')) {
"Folder $_ is empty"
rd $_ -confirm
}
}
Read-Host "Press ENTER to finish ... "
Re: Add <genre> info to directoryname and transfer all files form old dir to new dir with extended name
Hi NotNull,
I'd like to thank you for your effective support. Due to the fact that I don't have access to my ABook machine (absence from home) I've tried your scripts with a set of "synthetic" test dirs and it seems to work for so far. What I've learned from your support is, that it seems to be worth to have a closer look to the powershell environment. for demistifying this programming environment il will look for a book, can you, by the way, give me any recommendation for getting inside this stuff??
so I think that now all wishes to the fairy are done, so a last thank you for helping out an inspiring an old man to stay uptodate...
regs
Mike
I'd like to thank you for your effective support. Due to the fact that I don't have access to my ABook machine (absence from home) I've tried your scripts with a set of "synthetic" test dirs and it seems to work for so far. What I've learned from your support is, that it seems to be worth to have a closer look to the powershell environment. for demistifying this programming environment il will look for a book, can you, by the way, give me any recommendation for getting inside this stuff??
so I think that now all wishes to the fairy are done, so a last thank you for helping out an inspiring an old man to stay uptodate...
regs
Mike
#664 Personal license