Move Files 1.2 - Updated 10/01/2010

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Move Files 1.2 - Updated 10/01/2010

Post by trixmoto »

This script, as requested here, allows you to define a list of filetypes which are "buddy" files. This means a file which has the same name as, and is in the same folder as, a music track, but has a different extension. This script will move/copy these "buddy" files when you move/copy/autoorganise your files within MM. The default list contains just the "asd" extension.

As always, the installer can be downloaded from my website.

Code: Select all

'
' MediaMonkey Script
'
' NAME: MoveFiles 1.2
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 10/01/2010
'
' INSTALL: Copy to Scripts\Auto directory
'
' FIXES: Fixed buddy files not being renamed when necessary
'

Option Explicit

Dim Types : Types = Array("asd")
Dim CopyOver : CopyOver = True

Sub OnStartUp()
  Call Script.RegisterEvent(SDB,"OnBeforeTracksMove","MoveFiles")
End Sub

Sub MoveFiles(tracks,paths,move)
  Dim fso : Set fso = CreateObject("Scripting.FileSystemObject") 
  Dim i : i = 0
  Dim j : j = 0
  
  'loop through tracks being moved
  For i = 0 To tracks.Count-1
    Dim itm : Set itm = tracks.Item(i)
    Dim pos : pos = InStrRev(itm.Path,".")
    Dim oldf : oldf = Left(itm.Path,pos-1)
    Dim olde : olde = Mid(itm.Path,pos) 
    
    'loop through extensions to check
    For j = 0 To UBound(Types)
      pos = InStrRev(paths.Item(i),".")
      Dim newf : newf = Left(paths.Item(i),pos-1)
      Dim newe : newe = ""      
      Dim tmpe : tmpe = "."&Types(j)

      'check if either buddy file exists
      If fso.FileExists(oldf&tmpe) Then
        newe = tmpe
      Else
        If fso.FileExists(oldf&olde&tmpe) Then
          newe = olde&tmpe
        End If
      End If
      
      'move or copy buddy file 
      If Not (newe = "") Then
        Dim sour : sour = oldf&newe
        Dim dest : dest = newf&newe 
        If Not (sour = dest) Then
          Call GeneratePath(Left(dest,InStrRev(dest,"\")))
          If move Then
            Call fso.MoveFile(sour,dest)
          Else        
            Call fso.CopyFile(sour,dest,CopyOver)
          End If
        End If
      End If
    Next
  Next
End Sub

Function GeneratePath(pFolderPath)
  Dim fso : Set fso = CreateObject("Scripting.FileSystemObject") 
  GeneratePath = False
  If Not fso.FolderExists(pFolderPath) Then
    If GeneratePath(fso.GetParentFolderName(pFolderPath)) Then
      GeneratePath = True
      Call fso.CreateFolder(pFolderPath)
    End If
  Else
    GeneratePath = True
  End If
End Function
Last edited by trixmoto on Fri Oct 12, 2007 11:02 am, edited 3 times in total.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

:oops: Sorry, I have uploaded the installer now so it can (now) be downloaded from my website! :oops:
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

New version (1.1) can now be downloaded from my website. Changes include...

- Added attempt to find buddy file by appending extension as well
- Fixed full path is now generated before attempting to move/copy
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

An MM3 installation package is now available for this script. A restart of MM is required though because there is a bug with MM3 which means the events are not correctly registered during the installation.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
hernil
Posts: 35
Joined: Mon Dec 03, 2007 9:34 am

Post by hernil »

Is there any way of making this script move the .cue and .log file EAC makes when ripping an album to flac together with the actual flac files if I rip it to a folder monitored by MM?
nohitter151
Posts: 23640
Joined: Wed Aug 09, 2006 10:20 am
Location: NJ, USA
Contact:

Post by nohitter151 »

hernil wrote:Is there any way of making this script move the .cue and .log file EAC makes when ripping an album to flac together with the actual flac files if I rip it to a folder monitored by MM?
Yes, you should download the script and try it. It was originally written to move .cue files, see here.
MediaMonkey user since 2006
Need help? Got a suggestion? Can't find something?

Please no PMs in reply to a post. Just reply in the thread.
Linkowich
Posts: 4
Joined: Tue Sep 05, 2006 5:21 pm
Location: Stockholm, Sweden

Post by Linkowich »

Trixmoto: Thanks for a great script!

But, is there a way to get the script to also update the "buddy" filename when using auto organize so that it will still match the new name of the audio file?

Right now it seems to move the files alright, but if the audio file is auto-renamed the buddy file - audio file link will be lost.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Re: Move Files 1.1 [MM2+3]

Post by trixmoto »

Thanks! This issue is already on my list to be fixed so watch this space! :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
JClouseau

Re: Move Files 1.1 [MM2+3]

Post by JClouseau »

I've made modifications to trixmoto's MoveFiles script v1.1 to move/rename related files by extension (i.e. filename.mp3 could have children filename.cdg or filename.mp3.cdg). Working for MM3 and does everything except if the file is in use, then not so much.

Code: Select all

'
' MediaMonkey Script
'
' NAME: MoveFiles 1.1.J
'
' AUTHOR: trixmoto (http://trixmoto.net)
' MOD: J.Standlee (http://standleefamily.com)
' DATE : 5/7/2009
'
' INSTALL: Copy to Scripts\Auto directory
'
' FIXES: Added attempt to find buddy file by appending extension as well
'        Fixed full path is now generated before attempting to move/copy
'
Option Explicit

Dim aryExtensions : aryExtensions = Array("asd","cdg")
Dim CopyOver : CopyOver = True

Sub OnStartUp
  Script.RegisterEvent SDB, "OnBeforeTracksMove", "MoveFiles"
End Sub


Sub MoveFiles(tracks,paths,move)
    Dim fso : Set fso = CreateObject("Scripting.FileSystemObject") 
    Dim i,j

    'loop through tracks being moved
    For i = 0 To tracks.Count-1
        Dim oldFileObject : Set oldFileObject = tracks.Item(i)
        Dim oldFileFullPathNoExt : oldFileFullPathNoExt = Left(oldFileObject.Path,InStrRev(oldFileObject.Path,".")) 
        Dim newFileFullPathNoExt : newFileFullPathNoExt = Left(paths.Item(i), InStrRev(paths.Item(i),".")) 

        'msgbox(tracks.Item(i).path & vbcrlf & paths.Item(i))

        'loop through extensions to check
        For j = LBound(aryExtensions) To UBound(aryExtensions)
            Dim doit : doit = False
            Dim oldFileFullPath_Child : oldFileFullPath_Child = oldFileFullPathNoExt & aryExtensions(j)
            Dim newFileFullPath_Child : newFileFullPath_Child = newFileFullPathNoExt & aryExtensions(j)
            Dim oldFileFullPath_Child2 : oldFileFullPath_Child2 = oldFileObject.Path & "." & aryExtensions(j)
            Dim newFileFullPath_Child2 : newFileFullPath_Child2 = paths.Item(i)      & "." & aryExtensions(j)

            'check if either buddy file exists
            If fso.FileExists(oldFileFullPath_Child) Then
                doit = True
            Else
                If fso.FileExists(oldFileFullPath_Child2) Then
                    doit = True
                    oldFileFullPath_Child = oldFileFullPath_Child2
                    newFileFullPath_Child = newFileFullPath_Child2
                End If
            End If

            'move or copy buddy file 
            If doit Then
                Dim dest : dest = Left(newFileFullPath_Child, InStrRev(newFileFullPath_Child,"\"))
                Call GeneratePath(dest)
                If move Then
                    fso.MoveFile oldFileFullPath_Child, newFileFullPath_Child
                Else
                    fso.CopyFile oldFileFullPath_Child, newFileFullPath_Child, CopyOver
                End If
            End If
        Next
    Next
    set fso = nothing
End Sub



Function GeneratePath(pFolderPath)
    Dim fso : Set fso = CreateObject("Scripting.FileSystemObject") 
    GeneratePath = False
    If Not fso.FolderExists(pFolderPath) Then
        If GeneratePath(fso.GetParentFolderName(pFolderPath)) Then
            GeneratePath = True
            Call fso.CreateFolder(pFolderPath)
        End If
    Else
        GeneratePath = True
    End If
    set fso = nothing
End Function
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Re: Move Files 1.2 [MM2+3] - Updated 10/01/2010

Post by trixmoto »

New version (1.2) is now available to download from my website. Changes include...

- Fixed buddy files not being renamed when necessary
- Added update server to installation package
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Rojer
Posts: 65
Joined: Tue Aug 22, 2006 5:06 am

Re: Move Files 1.2 - Updated 10/01/2010

Post by Rojer »

Hey Trix

have been using this scrit for a couple of years now and it brought tremendous help, organizing thousands of files with buddy CDG. Wonderful thing is that it seems to be fully compatible with the "undo auto-organize script". Handy when something goes wrong.


Today I notice the weirdest thing : copying won't carry the buddy file anymore. Auto-organize still perfect. I fail to see how tis can be, apart from the fact my system underwent one major change: switched to W7. Disk is still fat32, search index off.

Either "send to/copy", "drag & drop in explorer window" or "synching" will leave the buddy file behind. Considering auto-organize and undo still work flawlessly, is there any chance that this would be relqted to the W7 switch ?

Thanks for reading. And even more for writing this code : I just can't imagine doing without it :)
Roj.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Re: Move Files 1.2 - Updated 10/01/2010

Post by trixmoto »

Well if it's not moving then I think there's only two reasons, (1) the event is not firing, which I think is unlikely, or (2) Windows is blocking the move, although I don't understand why it would block a copy and not an auto-organise, which is basically the same thing as far as Windows is concerned. :-?
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
frederic

Re: Move Files 1.2 - Updated 10/01/2010

Post by frederic »

Well as i said in the other post. I downloaded the "moving files" script because i want to move ableton's als files. I can move the asd file without problems but i can't move the als file and i don't know why. i edited the variable as i should do, the mp3 file and the als file have the same name so i don't know what to do. Any light would be great. Thanks
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Re: Move Files 1.2 - Updated 10/01/2010

Post by trixmoto »

Well it doesn't make sense that it would move one type of file but not another, if they have the same names and just different extensions. Are you sure that you are editing the correct file? I'm not trying to be patronising, I just mean that sometimes Vista creates copies of files in the "VirtualStore" and this can cause problems with knowing which file is actually being used.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
frederic

Re: Move Files 1.2 - Updated 10/01/2010

Post by frederic »

I'm on windows 7. So maybe it's a windows 7 bug?
Post Reply