Skip to content

Instantly share code, notes, and snippets.

@Beyarz
Created August 8, 2024 21:13
Show Gist options
  • Save Beyarz/a4de39a45d557d81479bb93147bc7442 to your computer and use it in GitHub Desktop.
Save Beyarz/a4de39a45d557d81479bb93147bc7442 to your computer and use it in GitHub Desktop.
Rename every folder in a directory
# frozen_string_literal: true
# Put me in a folder where you want to bulk rename every folder
# In this case, this script will rename every folder from "Photos from YEAR" to "YEAR" only
# Run: ruby bulk_rename.rb
folders = Dir.entries('.').reject { ['.', '..'].include? _1 }
folders.each do |folder|
File.rename(File.join(Dir.pwd, folder), File.join(Dir.pwd, folder.delete_prefix("Photos from ")))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment