From a4c56fb432e8fd75df930647427bcb582e989344 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 21 Feb 2025 11:21:35 +0100 Subject: Add a script changing file extensions --- bin/rename.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 bin/rename.rb (limited to 'bin') diff --git a/bin/rename.rb b/bin/rename.rb new file mode 100755 index 0000000..654f220 --- /dev/null +++ b/bin/rename.rb @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# This Source Code Form is subject to the terms of the Mozilla Public License, +# v. 2.0. If a copy of the MPL was not distributed with this file, You can +# obtain one at https://mozilla.org/MPL/2.0/. -} + +# frozen_string_literal: true + +require 'fileutils' + +if ARGV.length == 3 + Dir.glob("#{ARGV[0]}/**/*.#{ARGV[1]}").each do |original| + new_name = original.sub /\.#{Regexp.escape(ARGV[1])}$/, ARGV[2] + + puts "Renaming #{original} to #{new_name}." + FileUtils.mv original, new_name + end +else + $stderr.puts <<~USAGE + Usage: + #{$0} directory old_extension new_extension + + The directory is searched recursively. + The old and new extensions should not begin with a dot (.). + + Example: #{$0} src ce.vue vue + Changes the extensions of all files matching src/**/*.ce.vue to .vue. + USAGE + exit 1 +end -- cgit v1.2.3