Created
September 20, 2010 07:53
-
-
Save ecerulm/587562 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fso = new ActiveXObject("Scripting.FileSystemObject"); | |
var folders = new Array(); | |
function Initialize_enumFolders (path) | |
{ | |
if (fso.driveExists(fso.GetDriveName(path)) && fso.folderExists(fso.GetDriveName(path))) | |
enumFolders(path); | |
} | |
function enumFolders(path) | |
{ | |
var objFolder = fso.GetFolder(path); | |
var fl = new Enumerator(objFolder.Subfolders); | |
for (; !fl.atEnd(); fl.moveNext()) | |
{ | |
f = fl.item(); | |
enumFolders(f); | |
folders[folders.length]=f.path; | |
} | |
} | |
var ITTrackKindFile = 1; | |
var iTunesApp = WScript.CreateObject("iTunes.Application"); | |
var deletedTracks = 0; | |
var mainLibrary = iTunesApp.LibraryPlaylist; | |
var tracks = mainLibrary.Tracks; | |
var numTracks = tracks.Count; | |
var i; | |
var iTunesFiles=new Array (); | |
var fso, tf; | |
while (numTracks != 0) | |
{ | |
var currTrack = tracks.Item(numTracks); | |
// is this a file track? | |
if (currTrack.Kind == ITTrackKindFile) | |
{ | |
// write info about the track to a file | |
iTunesFiles[iTunesFiles.length]=currTrack.Location; | |
} | |
numTracks--; | |
} | |
Initialize_enumFolders ("C:\\Documents and Settings\\ecerulm\\Mis documentos\\Mi música\\iTunes\\iTunes Music"); | |
var filesystemFiles = new Array(); | |
for(var i=0; i < folders.length; i++) { | |
f =folders[i]; | |
f = fso.GetFolder(f); | |
fe = new Enumerator(f.files); | |
for(;!fe.atEnd(); fe.moveNext()) { | |
filesystemFiles[filesystemFiles.length] = fe.item().path; | |
} | |
} | |
function areArraysEqual(array1, array2) { | |
var temp = new Array(); | |
var diff = new Array(); | |
// Put all the elements from array1 into a "tagged" array | |
for (var i=0; i<array1.length; i++) { | |
key = array1[i]; | |
// Use "typeof" so a number 1 isn't equal to a string "1". | |
if (temp[key]) { temp[key]++; } else { temp[key] = 1; } | |
// temp[key] = # of occurrences of the value (so an element could appear multiple times) | |
} | |
// Go through array2 - if same tag missing in "tagged" array, not equal | |
for (var i=0; i<array2.length; i++) { | |
key = array2[i]; | |
if (!temp[key]) { | |
diff[diff.length] = key; | |
temp[key] = 1; //to eliminate duplicates | |
} | |
} | |
return diff; | |
} | |
diff = areArraysEqual(iTunesFiles,filesystemFiles); | |
tf = fso.CreateTextFile("filesnotlinked.txt", true); | |
for(i=0;i<diff.length;i++) { | |
tf.WriteLine(diff[i]); | |
} | |
tf.Close(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment