Move your iTunes Library Completely (VBScript)
- Details
- Category: Scripts and Code
- Published on Saturday, 22 October 2011 01:18
- Written by Christian Dunn
There are many reasons you may wish to move your iTunes library. It may be taking up more space than you have on your C drive, you may wish to move it to another computer, or in an office environment you might accidentally be storing your music on the servers. This script is very simple to configure and steps the user through the process.
The full code is shown below. VBScript works on all versions of Windows.
Copy and Paste the following code into notepad and save it as a .vbs file. The script will then run in windows when you open it.
Option Explicit
Dim strPath,x,filesys,servershare,sharedfolder,wshShell,strUserName,folder'---------------------------------------------------------------------
' This script relocates your iTunes library to a new location.
' This is designed to assist users in moving iTunes from redirected My Document drives to their own machine.
' Written by Christian dunn 14/10/11
' http://www.chris.dunn.name'There is only one variable that needs to be updated.
'Select the appropriate option.
'Update this variable to specify the current network user share in a domain:
servershare = "\\myserver\users\"
'Instead of the above option, comment it out and use these options for non domain computers:
'servershare = "c:\Documents and Settings\" 'Windows XP
'servershare = "c:\Users\" 'Windows Vista/7
'---------------------------------------------------------------------'Set shell commands, system objects and iTunes path
Set wshShell = WScript.CreateObject( "WScript.Shell" )
set filesys=CreateObject("Scripting.FileSystemObject")
strUserName = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )
sharedfolder = servershare & strUserName & "\My Documents\My Music\iTunes"'Welcome message
WScript.Echo "This script assists in relocating your iTunes library. Please check that iTunes is closed."
WScript.Echo "Choose or create the new iTunes folder. Your current iTunes location is " & sharedfolder & "."'Prompt to select target location
strPath = SelectFolder( "" )
If strPath = vbNull Then
'No folder selected
WScript.Echo "Cancelled"
Else
'Confirm folder selection
x=MsgBox("Are you sure you want to move iTunes to """ & strPath & """",4,"Please confirm")
If x = 6 then
'If user responds yes
If filesys.FolderExists(sharedfolder) Then
'Get folder size and prompt user.
set folder = filesys.GetFolder(sharedfolder)
WScript.Echo "Your data will now be transferred. This may take a long while depending on the size of your library. Your current library size is " & round(folder.Size/1024/1024,2) &"MB. Press OK to begin."
'Copy Files
filesys.CopyFolder sharedfolder, strPath
'Notify user of next steps
WScript.Echo "Your copy is complete. Hold down shift while starting iTunes, select " & """Choose Library""" & " and select the " & """iTunes Library.itl""" & " file in your newlocation to update iTunes. Press OK when completed."
'Prompt to remove old files
x=MsgBox("Would you like to remove the old iTunes library?",4,"Please confirm")
If x = 6 then
'remove old files
filesys.DeleteFolder sharedfolder
WScript.Echo "Finished."
End If
Else
'If iTunes source folder cannot be found
WScript.Echo "Your iTunes folder has already been moved or cannot be found in the specified location of """ & sharedfolder & """."
End If
Else
'If user cancels select folder dialog
WScript.Echo "Cancelled."
End IF
End If
Function SelectFolder( myStartFolder )
' This function opens a "Select Folder" dialog and will
' return the fully qualified path of the selected folder' Standard housekeeping
Dim objFolder, objItem, objShell
' Custom error handling
On Error Resume Next
SelectFolder = vbNull' Create a dialog object
Set objShell = CreateObject( "Shell.Application" )
Set objFolder = objShell.BrowseForFolder( 0, "Select Folder", 0, myStartFolder )' Return the path of the selected folder
If IsObject( objfolder ) Then SelectFolder = objFolder.Self.Path' Standard housekeeping
Set objFolder = Nothing
Set objshell = Nothing
On Error Goto 0
End Function