Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/tclsh
- # Convert to lower and dash for spaces.
- if { $argc != 1 } {
- puts "Requires a file path."
- exit
- }
- set filepath [lindex $argv 0]
- puts "File path: $filepath"
- if { ![file isdirectory $filepath] } {
- puts "File path is not a directory."
- exit
- }
- proc generatefilename { filename } {
- set temp [string trim [string tolower $filename]]
- regsub -all { } $temp {-} filename
- return $filename
- }
- proc getfilename { file } {
- if { [regexp {.+/(.+)} $file match filename] } {
- return $filename
- }
- puts "Regexp failed for $file"
- return $file
- }
- # check leading slash for filepath
- if { ![string eq [string index $filepath end] {/}] } {
- append filepath {/}
- }
- foreach file [lsort [glob -nocomplain -directory $filepath "*\.*"]] {
- if { ![file isfile $file] } {
- puts "Skipping $file"
- continue
- }
- set filename [getfilename $file]
- set newfilename [generatefilename $filename]
- puts "Renaming $filename to $newfilename"
- set newfilepath "${filepath}${newfilename}"
- file rename $file $newfilepath
- }
- puts "Done!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement