summaryrefslogtreecommitdiffhomepage
path: root/musicSorter.rb
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2020-04-26 01:18:08 -0400
committerGitHub <[email protected]>2020-04-26 01:18:08 -0400
commit46b93930c85879d700a076496d3800f7398c4cb4 (patch)
tree3fc4869511e63e7ecb992c916422ff67185ff09a /musicSorter.rb
parentc4ae1b99a2d16f5fc5a2d76c4ec8082c95f3591c (diff)
downloadmusicSorter-46b93930c85879d700a076496d3800f7398c4cb4.tar.gz
musicSorter-46b93930c85879d700a076496d3800f7398c4cb4.zip
Simplified for loops, added script parameters
Diffstat (limited to 'musicSorter.rb')
-rw-r--r--musicSorter.rb30
1 files changed, 12 insertions, 18 deletions
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)