aboutsummaryrefslogtreecommitdiff
path: root/private_dot_local/bin/executable_rename-fat32
diff options
context:
space:
mode:
authortwells46 <173561638+twells46@users.noreply.github.com>2025-12-31 13:28:05 -0600
committertwells46 <173561638+twells46@users.noreply.github.com>2025-12-31 13:28:05 -0600
commit2140ab51deed88e90eafebf9520fa5f9995dc7c9 (patch)
tree03cf1dcd2900495c1efb79aaa85f3254ecd5fb87 /private_dot_local/bin/executable_rename-fat32
parentff8f50638e4b17a9d7cc88d2f0d9560b7effce39 (diff)
Migrate from stow
Diffstat (limited to 'private_dot_local/bin/executable_rename-fat32')
-rw-r--r--private_dot_local/bin/executable_rename-fat3234
1 files changed, 34 insertions, 0 deletions
diff --git a/private_dot_local/bin/executable_rename-fat32 b/private_dot_local/bin/executable_rename-fat32
new file mode 100644
index 0000000..25fc947
--- /dev/null
+++ b/private_dot_local/bin/executable_rename-fat32
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby
+# Encoding : UTF-8
+
+class RenameFAT32
+ def initialize(*args)
+ @files = args.map do |file|
+ File.expand_path(file)
+ end
+ end
+
+ def make_fat32_compliant(value)
+ # Remove characters not allowed in fat32
+ value = value.to_s.gsub(/([\?\/\*\|:;"”“<>])/, "").strip
+ # Double spaces
+ value = value.gsub(/ {2,}/," ")
+ # Bad quotes
+ value = value.gsub('’', "'")
+ return value
+ end
+
+ def run
+ @files.each do |file|
+ dirname = File.dirname(file)
+ extname = File.extname(file)
+ basename = File.basename(file, extname)
+ new_basename = make_fat32_compliant(basename)
+ new_file = File.join(dirname, new_basename+extname)
+
+ File.rename(file, new_file) if file != new_file
+ end
+
+ end
+end
+RenameFAT32.new(*ARGV).run()