by JonSenior » Fri May 26, 2006 10:23 am
OK. Boredom set in. Consequently it now trims empty directories after operating on the files.
Bex: To make this work for you, you need to replace
Code: Select all
tmp = Replace(itm.Path, " - ", "-")
tmp = Replace(tmp, " ", "_")
with
Code: Select all
tmp = Replace(itm.Path, "_", " ")
This doesn't update the tree on the left hand side, but manually collapsing the tree and then re-opening it will cause a refresh. Not sure how to do this in code so it is left as an exercise for the reader. I'll crosspost this to the Scripts forum in case anyone else finds it useful.
Hope this helps.
Code: Select all
' A simple script that adds underscores to path names.
Sub AddUnderscores
' Define variables
Dim list, itm, i, tmp, res, fso, dirList, key
Set fso = CreateObject("Scripting.FileSystemObject")
Set dirList = CreateObject("Scripting.Dictionary")
' Get list of selected tracks from MediaMonkey
Set list = SDB.CurrentSongList
' Process all selected tracks
res = SDB.MessageBox( "About to (possibly) modify " + CStr(list.count) + " files. Continue?", mtConfirmation, Array(mbOk, mbCancel))
if res = mrOK then
For i=0 To list.count-1
Set itm = list.Item(i)
' Get the folder in which itm resides
key = fso.GetFile(itm.Path).ParentFolder
If not dirList.exists(key) Then
dirList.Add key, key
End If
tmp = Replace(itm.Path, " - ", "-")
tmp = Replace(tmp, " ", "_")
itm.Path = tmp
itm.UpdateDB
Next
End If
list = dirList.Items
For each i in list
Call DeleteDirectoryIfEmpty(fso.GetFolder(i))
Next
End Sub
' Recursively delete empty directories
Sub DeleteDirectoryIfEmpty(dir)
dim parent
If dir.Files.Count = 0 and dir.SubFolders.Count = 0 Then
Set parent = dir.ParentFolder
dir.Delete
Call DeleteDirectoryIfEmpty(parent)
End If
End Sub
OK. Boredom set in. Consequently it now trims empty directories after operating on the files.
[b]Bex:[/b] To make this work for you, you need to replace
[code] tmp = Replace(itm.Path, " - ", "-")
tmp = Replace(tmp, " ", "_")
[/code]
with
[code] tmp = Replace(itm.Path, "_", " ")
[/code]
This doesn't update the tree on the left hand side, but manually collapsing the tree and then re-opening it will cause a refresh. Not sure how to do this in code so it is left as an exercise for the reader. I'll crosspost this to the Scripts forum in case anyone else finds it useful.
Hope this helps.
[code]' A simple script that adds underscores to path names.
Sub AddUnderscores
' Define variables
Dim list, itm, i, tmp, res, fso, dirList, key
Set fso = CreateObject("Scripting.FileSystemObject")
Set dirList = CreateObject("Scripting.Dictionary")
' Get list of selected tracks from MediaMonkey
Set list = SDB.CurrentSongList
' Process all selected tracks
res = SDB.MessageBox( "About to (possibly) modify " + CStr(list.count) + " files. Continue?", mtConfirmation, Array(mbOk, mbCancel))
if res = mrOK then
For i=0 To list.count-1
Set itm = list.Item(i)
' Get the folder in which itm resides
key = fso.GetFile(itm.Path).ParentFolder
If not dirList.exists(key) Then
dirList.Add key, key
End If
tmp = Replace(itm.Path, " - ", "-")
tmp = Replace(tmp, " ", "_")
itm.Path = tmp
itm.UpdateDB
Next
End If
list = dirList.Items
For each i in list
Call DeleteDirectoryIfEmpty(fso.GetFolder(i))
Next
End Sub
' Recursively delete empty directories
Sub DeleteDirectoryIfEmpty(dir)
dim parent
If dir.Files.Count = 0 and dir.SubFolders.Count = 0 Then
Set parent = dir.ParentFolder
dir.Delete
Call DeleteDirectoryIfEmpty(parent)
End If
End Sub[/code]