From 46b93930c85879d700a076496d3800f7398c4cb4 Mon Sep 17 00:00:00 2001 From: realtradam Date: Sun, 26 Apr 2020 01:18:08 -0400 Subject: Simplified for loops, added script parameters --- musicSorter.rb | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'musicSorter.rb') diff --git a/musicSorter.rb b/musicSorter.rb index 73dcd8b..30c4f75 100644 --- a/musicSorter.rb +++ b/musicSorter.rb @@ -9,6 +9,11 @@ errors = Array.new #Characters that are removed from the file/folder names as they are considered illegal in Windows illegalCharacter = Array['/', '?', '\\', ':', '*', '"', '<', '>', '|'] +songsDirectory = ARGV[0]#Where you want your organized songs to end up +if !Dir.exist?(songsDirectory) + puts "Invalid Directory Given" +end + #All extensions you want considered and moved fileExtensions = Array["mp3", "m4a", "wma"]#Note that .ogg files do not work, tags do not get read correctly for extension in fileExtensions @@ -70,29 +75,18 @@ for extension in fileExtensions #How we want our songs to be formatted songFileName = track + title + "." + extension - #Individually checking each folder if it exists, if not make it + #Check if the folder exists, if not make it #Once the folder is confirmed to exist, it will move and rename the song to the correct location begin - if Dir.exist?(songFolderGenre) - if Dir.exist?(songFolderGenre + songFolderArtist) - if Dir.exist?(songFolderGenre + songFolderArtist + songFolderAlbum) - if !File.exist?(songFolderGenre + songFolderArtist + songFolderAlbum + songFileName) - FileUtils.mv song, songFolderGenre + songFolderArtist + songFolderAlbum + songFileName - end - else - Dir.mkdir(songFolderGenre + songFolderArtist + songFolderAlbum) - FileUtils.mv song, songFolderGenre + songFolderArtist + songFolderAlbum + songFileName - end + if Dir.exist?(songsDirectory + songFolderGenre + songFolderArtist + songFolderAlbum) + if !File.exist?(songsDirectory + songFolderGenre + songFolderArtist + songFolderAlbum + songFileName) + FileUtils.mv song, songsDirectory + songFolderGenre + songFolderArtist + songFolderAlbum + songFileName else - Dir.mkdir(songFolderGenre + songFolderArtist) - Dir.mkdir(songFolderGenre + songFolderArtist + songFolderAlbum) - FileUtils.mv song, songFolderGenre + songFolderArtist + songFolderAlbum + songFileName + errors.push("ERROR, SONG ALREADY EXISTS AT " + songsDirectory + songFolderGenre + songFolderArtist + songFolderAlbum + songFileName + " CAN'T MOVE FROM " + song) end else - Dir.mkdir(songFolderGenre) - Dir.mkdir(songFolderGenre + songFolderArtist) - Dir.mkdir(songFolderGenre + songFolderArtist + songFolderAlbum) - FileUtils.mv song, songFolderGenre + songFolderArtist + songFolderAlbum + songFileName + FileUtils.mkdir_p(songsDirectory + songFolderGenre + songFolderArtist + songFolderAlbum) + FileUtils.mv song, songsDirectory+ songFolderGenre + songFolderArtist + songFolderAlbum + songFileName end rescue Errno::ENOENT#Incase the program tries to save to a folder not yet created, shouldnt ever happen errors.push("ERROR, FILE OR FOLDER NAME ERROR AT " + song) -- cgit v1.2.3