Last active
February 7, 2019 12:41
-
-
Save sepisoad/4f4dbf47ff3534976d6c3d41a92daa22 to your computer and use it in GitHub Desktop.
rename all files in a dir to lowercase or uppercase (name only / extension only / full name)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(local mfs (require "minifs")) | |
(local str (require "std.string")) | |
(if (not (= 3 (# arg))) | |
(do (print "not valid input arguments") | |
(os.exit))) | |
(if (not (or (= (. arg 1) "-l") (= (. arg 1) "-u"))) | |
(do (print "first arg must be a function [-l or -u]") | |
(os.exit))) | |
(local func (if (= (. arg 1) "-l") "lower" "upper")) | |
(if (not (or (= (. arg 2) "-n") (= (. arg 2) "-x") (= (. arg 2) "-f"))) | |
(do (print "first arg must be a function [-l or -u]") | |
(os.exit))) | |
(local mode (if (= (. arg 2) "-n") "name" | |
(= (. arg 2) "-x") "extension" | |
"full")) | |
(if (not (mfs.exists (. arg 3))) | |
(do | |
(print "destination path does not exist") | |
(os.exit))) | |
(local path (. arg 3)) | |
(local get-file-name (mfs.files path)) | |
(fn trans [func mode file] | |
(let [nme (. (str.split file "%.") 1) | |
ext (. (str.split file "%.") 2) | |
tfn (if (= func "lower") string.lower string.upper)] | |
(if (= "full" mode) (.. (tfn nme) "." (tfn ext)) | |
(= "name" mode) (.. (tfn nme) "." ext) | |
(= "extension" mode) (.. nme "." (tfn ext))))) | |
(do | |
(var file-name (get-file-name)) | |
(while (~= nil file-name) | |
(when (not (or (= file-name ".") (= file-name ".."))) | |
(mfs.move | |
(.. path "/" file-name) | |
(.. path "/" (trans func mode file-name)))) | |
(set file-name (get-file-name)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the script is written in fennel script
this file has nothing to do with clojure or clojurescript.
I had to name the script as a clojure file in order to fool github to give the code a proper color scheme,
examples: