Update 200901 THIS IS OUT OF DATE, please look for RegExp Find & Replace at http://www.mediamonkey.com/forum/viewto ... =2&t=28510 for a much more sophistated script.
I correct my small script with 2 Subs - thanx for the feedback!
|>Enumerate the selected tracks, optionally add the correct formated track# to the title
|>Kill leading numbers (optionally with spaces around), an undo I once needed
Hope you'll find it usefull.
Code: Select all
' Use at your own risk, V 1.1
' V1.1 less than 10 tracks -> error in String-Func; add to track now correct formated
' Enumerates the selected track in the displayed order
' If wanted track# (incl. leading zeros according to number of tracks)
' can be added to the title, an undo sub is included ;-), Scripts.ini;
' [EnumerateTracks]
' FileName=EnumerateTracks.vbs
' ProcName=EnumerateTracks
' Order=3
' DisplayName=Enumerate Tracks
' Description=Enumerate the selected tracks
' Language=VBScript
' ScriptType=0
' [KillLeadingNumbers]
' FileName=EnumerateTracks.vbs
' ProcName=KillLeadingNumbers
' Order=4
' DisplayName=Kill leading Numbers
' Description=Kills all leading numbers in selected tracks´ titles
' Language=VBScript
' ScriptType=0
Option Explicit
Sub EnumerateTracks
'Define variables & Constants
Dim i, CurrentDigits, CurrentDecade, StringOfZeros, MaxDigitsToAdd, AddToTitle, Progress
Set Progress = SDB.Progress : Progress.Text = SDB.Localize("Enumerate...")
' Get Tracklist
With SDB.SelectedSongList
If .count < 2 Then SDB.MessageBox "Select more than 1 title...", mtWarning, Array(mbOk) : Exit Sub
AddToTitle = msgbox("Also add Track# to the title?", vbYesNoCancel + vbDefaultButton2,"Enumerate Track")
If AddToTitle = vbCancel then Exit Sub
Progress.MaxValue = .count
' int(log(.count)/log(10)) <=> digits of last track - 1 (no log10 defined in vbs?)
MaxDigitsToAdd = int(log(.count)/log(10))
StringOfZeros = String(MaxDigitsToAdd + 1, "0") 'V11: string func does not accept 0 as length
CurrentDigits = 0 : CurrentDecade = 10
For i=1 To .count
' check digits of counter i, don't know how fast the ^-op is .. better safe than sorry
If i = CurrentDecade then
CurrentDigits = CurrentDigits + 1
CurrentDecade = 10 ^ (CurrentDigits + 1) 'V11: + 1 added
End If
.item(i-1).TrackOrder = i
If AddToTitle = vbYes Then
.item(i-1).Title = left(StringOfZeros, MaxDigitsToAdd - CurrentDigits) & i _
& " " & .item(i-1).Title
End If
.item(i-1).UpdateDB
Progress.Value = i 'V11: No +1
if Progress.Terminate then Exit For
Next
End With
Set Progress = Nothing
End Sub
Sub KillLeadingNumbers
Dim LeavingSpace, RegularExpression, i, Progress
Set Progress = SDB.Progress : Progress.Text = SDB.Localize("Enumerate...")
Set RegularExpression = New RegExp : RegularExpression.pattern = "^\s*\d*" ' Leadings spaces also
With SDB.SelectedSongList
If .count = 0 Then SDB.MessageBox "Select something...", mtWarning, Array(mbOk) : Exit Sub
LeavingSpace = msgbox("Space(s)after leading numbers required?", vbYesNoCancel + vbDefaultButton1,"Kill Leading Numbers")
If LeavingSpace = vbCancel then Exit Sub
If LeavingSpace = vbYes then RegularExpression.pattern = "^\s*\d*\s+"
' this will kill leading spaces even if no number present
Progress.MaxValue = .count
For i=1 To .count
.item(i-1).Title = RegularExpression.Replace( .item(i-1).Title, "")
.item(i-1).UpdateDB
Progress.Value = i+1
if Progress.Terminate then Exit For
Next
End With
Set Progress = Nothing
End Sub