Tuesday, November 10th

Did you know that how you name your uploaded files matter to Google Search Results?

For more information you can watch the Google WebMaster's video here.

In short, here's how you don't want to name your files:

  1. Obscurely: 023423.jpg
  2. With Spaces: 1969 chevy camaro.jpg
  3. With Underscores: 1969_chevy_camaro.jpg
  4. With Capital Letters: 1969_Chevy_Camaro.jpg

Instead, here's how you should name your files:

  • ​Descriptively, lower-case, with hyphens: 1969-chevy-camaro.jpg

I ran into this SEO issue when uploading my sermons, discussion guides, and slides online. On my Dropbox account where I save all my ministry stuff I had all kinds of crazy names for my files like "The Vine.pptx" or "2015-09-13 Sermon discuss" and when I realized this was going to be a long, hairy process I thought to myself, "This is a perfect job for a Ruby script!"

So without further ado, here is a little (literally less than 1K) script you can run to automatically rename all the files in a folder and make them SEO friendly. It's not a perfect solution, it won't solve your obscurely named files, but it will replace your white space and your underscores with hyphens!

Note: If you are running Windows or Linux you will need to install Ruby first. Mac users, you're all set :)

Download or create your own Ruby file and paste the following script:

puts ".\n"*5
puts "This script will take all files of the extension you specify, lowercase the name, and replace white space with a hyphen."
puts "This file must be within the given folder. If it is not, you may ctrl+c to stop this script at any time."
puts "Please type the extension below without the period:"
filetype = gets.chomp()
Dir.glob("*.#{filetype}").each do |file|
  newfile = file.downcase.gsub(/ /, ' ' => '-')
  newfile = newfile.gsub(/_/, '-')
  File.rename(file, newfile)
end
puts "Your file(s) have been renamed."

By the way, I am having trouble understanding how to pass hash through my gsub method so that I can look for white space or underscores instead of calling gsub twice. Comment below if you can explain :) 

Subscribe

Subscribe