Advertisement
jonathanpb

itunesautoimport.vbs

Oct 8th, 2024 (edited)
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VBScript 1.95 KB | Source Code | 0 0
  1. 'iTunes does not see changes to the 'Automatically Add to iTunes' folder on a network location.
  2. 'This script can be run at regular intervals. There is no call to add a track to the library without conversion,
  3. 'But if you create a playlist with the contents of the folder, iTunes will import the files and move them to the library.
  4. 'The script then deletes the playlist created to trigger the import.
  5.  
  6. 'Update folderPath = "\\nas\iTunes\iTunes Music\Automatically Add to iTunes" with the correct path for your import folder.
  7.  
  8. ' Define the folder path as a variable
  9. Dim folderPath
  10. folderPath = "\\nas\iTunes\iTunes Music\Automatically Add to iTunes"
  11.  
  12. ' Function to check if a folder contains files, excluding a specific subfolder
  13. Function ContainsFiles(folder, excludeFolderName)
  14.     Dim subFolder, file
  15.     ' Check files in the current folder
  16.    For Each file In folder.Files
  17.         ContainsFiles = True
  18.         Exit Function
  19.     Next
  20.     ' Recursively check subfolders, except the excluded one
  21.    For Each subFolder In folder.SubFolders
  22.         If LCase(subFolder.Name) <> LCase(excludeFolderName) Then
  23.             If ContainsFiles(subFolder, excludeFolderName) Then
  24.                 ContainsFiles = True
  25.                 Exit Function
  26.             End If
  27.         End If
  28.     Next
  29.     ContainsFiles = False
  30. End Function
  31.  
  32. ' Check if the folder exists
  33. Dim objFSO, objFolder
  34. Set objFSO = CreateObject("Scripting.FileSystemObject")
  35.  
  36. If objFSO.FolderExists(folderPath) Then
  37.     Set objFolder = objFSO.GetFolder(folderPath)
  38. Else
  39.     WScript.Quit
  40. End If
  41.  
  42. ' Check if the folder or its subfolders (excluding "not added") contain files
  43. If Not ContainsFiles(objFolder, "not added") Then
  44.     ' If no files found
  45.    WScript.Quit
  46. Else
  47.     ' Add to iTunes
  48.    Dim iTunesApp
  49.     Set iTunesApp = WScript.CreateObject("iTunes.Application")
  50.     Dim List
  51.     Set List = iTunesApp.CreatePlaylist("zAutomatic")
  52.     List.AddFile(folderPath)
  53.     List.Delete()
  54. End If
  55.  
Tags: Script vbs itunes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement