I’ve written a little Ruby command line app that I use to keep TV Shows organized on my Mac harddrive. Given the nature of TV episode titles there are episodes which include the / character.
Being on a Mac, the filesystem actually allows me writing this file and if I manually rename the file with the / character in it everything is fine.
The moment Ruby’s File.rename runs in my script however I simply get a No such file or directory error because Ruby tries to read the / in the filename as a folder which should exist.
Here is an example:
Output path is /TV/Showname/Season 1/Showname - 1x07 - 5/1.mp4
Now rather than looking for the folder /Showname - 1x07 - 5/ and write to a 1.mp4 file inside of it, how can I tell ruby to simply take the filename (Showname - 1x07 - 5/1.mp4) and write it into the Season 1 folder as is?
Thanks for reading.
A weird one this, but because the backslash is used as a file-separator, it is converted to a colon in the filename used by Ruby. So to rename your file, replace the forward slash in the name with a colon.
So you would write something like: