Evaldas Paulauskas

iOS developer professionally, hobbyist gamedev

First steps in ruby scripting - File removal

15 Sep 2020 » ruby

I always had an interest in making use of programming to actually improve my daily life, but learning how to make apps/websites in various compiled languages, it always made it seem kind of like a hassle to actually just sit down and write something in 5min that helps me solve an issue at hand. Heard a lot about ruby, and how supposedely it is programmers best friend, I was skeptical, but after giving it a shot just now, its amazing. “Sure it may be dying” and perhaps python and do exactly the same thing in similar if not less amount of lines, don’t really care though. Ruby stands for simplicity and ease of use, I really love and respect that idea and want to support it by actually using it. Not all tools need to become bloated behemoths that can do everything. Anyway after just a few google searches got exactly what I needed, it worked perfectly. Below is the code I wrote for cleaning up some directories from subtitle files. I use VLC as a player and like to just drop folders into its playlist, but some of the tutorials that I have downloaded have a lot of junk in them which messes up VLC quite a lot. And maybe I am blind, but I can’t find an option on macOS VLC to disable subtitles for all videos, and not just the one you are currently on.

puts "Input path"
pathInput = gets.chomp
srtFiles = Dir.glob("#{pathInput}/**/*.srt")
htmlFiles = Dir.glob("#{pathInput}/**/*.html")
urlFiles = Dir.glob("#{pathInput}/**/*.url")

def deleteFiles (files)
    for file in files
        File.delete(file)
    end
end

deleteFiles srtFiles
deleteFiles htmlFiles
deleteFiles urlFiles