Underscore Addition!

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Underscore Addition!

by trixmoto » Fri Nov 30, 2007 11:43 am

Yeah, just replace...

Code: Select all

      tmp = Replace(itm.Path, " - ", "-")
      tmp = Replace(tmp, " ", "_")
...with...

Code: Select all

      tmp = Replace(itm.Path, "'", "`")

by Plazma » Fri Nov 30, 2007 4:22 am

Ya - just the song's filename - i manually go in and replace ' with ` so it can be read on my server. Just wondering if anyone could add it to the script - if so id appreciate it alot!:D

by trixmoto » Fri Nov 30, 2007 4:04 am

Which field are you trying to update, just the song path?

by Plazma » Thu Nov 29, 2007 4:32 pm

Can anyone mod this script to change apostrophes from ' to ` ... if you could that would be great i tried but Im not sure how

thx in advance!

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

by Bex » Fri May 26, 2006 9:12 am

Thanks alot!

/Bex

by JonSenior » Fri May 26, 2006 9:07 am

Bex: Just for you... I've just reversed the process. When I said that it doesn't understand paths, what I meant was that it doesn't break down the path into directories and check to see if any of those directories have been emptied by it's actions. It takes the full path for a file and adds (Or in this case, removes) underscore characters.

Install as per any other script. Select one or more files and it'll tell you how many files it's going to operate on, and give you an option to bail out.

I would advise backing up a directory of files and testing it on them first!

At some point I might look at extending this if I find it useful, but to be honest, it'll only be of academic interest to me. Good luck

Jon

Code: Select all

' A simple script that adds underscores to path names.
Sub AddUnderscores
  ' Define variables
  Dim list, itm, i, tmp, res, qty, message

  ' 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)

      tmp = Replace(itm.Path, "_", " ")
      itm.Path = tmp
      itm.UpdateDB
    Next
  End If
End Sub

by Bex » Fri May 26, 2006 8:59 am

I often have information in my folders which isn't in any tags. But sometimes I regret it...

/Bex

by Steegy » Fri May 26, 2006 8:49 am

@Bex:
Why don't you fix the tags/library and then use auto-organise with the correct info?
Anyway, I was just wondering.

by Bex » Fri May 26, 2006 8:47 am

That was fast! (I hope the girls not complaining :wink: )

Looking forward to the next version but I really would like it to work on full paths since I got alot of unwanted underscores in my paths which is time consuming to remove manually.

Great work.
/Bex

by JonSenior » Fri May 26, 2006 8:36 am

OK. One quick 'n' dirty hack later:

Code: Select all

' A simple script that adds underscores to path names.
Sub AddUnderscores
  ' Define variables
  Dim list, itm, i, tmp, res, qty, message

  ' 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)

      tmp = Replace(itm.Path, " ", "_")
      itm.Path = tmp
      itm.UpdateDB
    Next
  End If
End Sub
'sgot a message box an' everything! ;-) Currently it doesn't remove empty directories (In fact... it's blissfully unaware of path structures) and will require user interaction to tidy the directory tree.

Bex: If I get a few minutes this afternoon I'll look at extending the functionality to reverse the process.

Jon

by Bex » Fri May 26, 2006 8:17 am

What I meant was to rename the files using Auto-organise.
But I see now what you mean. The underscores would only appear between the "tags" in the filename which is not what you asked for.
e.g.
01 - Rolling Stones - Sympathy For The Devil.mp3
Would become (with this mask <Track#>_<Artist>_<Title>):
01_Rolling Stones_Sympathy For The Devil.mp3

I'll guess you'll have to write a script then...

PS If you make a script it would be nice to make it work both ways and optionally include the full path. Even nicer if it also renamed accompanying files.

/Bex

by JonSenior » Fri May 26, 2006 7:34 am

Bex: I may be being a little slow, but I can't see any way of using Auto-organise to replace spaces with underscores. Short of changing the tags before organising and changing them back afterwards!

Steegy: One quick and dirty hack on it's way then. <Shudders>

Jon[/b]

by Steegy » Fri May 26, 2006 7:29 am

The vbscript would need about max. 5 lines of code :-? :roll: :o

by Bex » Fri May 26, 2006 7:20 am

I'm not aware of any script that replace spaces with underscores in the filename. What you could do is to Auto-organise your files and include underscores in the mask.

/Bex

Top