|
|
Install the Linux rename utility
An easier of reading, powerful and short is the next one (manage Tcl regexps and admits -recursion, -capitularization....)
#!/usr/bin/env tclsh
# Juan Falgueras, 2004-12-28
# -- añado capitularizar.. pero falla
# «» regexp -indices {[:alpha:]} 01-pepe.mp3 que
# 1
# «» set que
# 3 3
# «» regexp -indices {[:alpha:]} ./01-pepe.mp3 que
# 1
# «» set que
# 5 5
# Además file rename se niega a cambiar a minúsculas
set Capitularizar 0
set capitularizar 0
set minusculizar 0
set recursivo 0
set pat ""
set reemp ""
if {$argc == 3 && [lindex $argv 0] == "-r"} {
set recursivo 1
set pat [lindex $argv 1]
set reemp [lindex $argv 2]
} elseif {$argc == 1 && [lindex $argv 0] == "-C"} {
set Capitularizar 1
} elseif {$argc == 1 && [lindex $argv 0] == "-c"} {
set capitularizar 1
} elseif {$argc == 1 && [lindex $argv 0] == "-m"} {
set minusculizar 1
} elseif {$argc != 2} {
puts stderr "USAR: $argv0 '(p)at' '..\1..'"
return 1
} else {
set pat [lindex $argv 0]
set reemp [lindex $argv 1]
}
proc procDir {d} {
global recursivo pat reemp capitularizar Capitularizar minusculizar
foreach f [glob "$d/*"] {
if {$recursivo && [file isdirectory $f]} {
procDir $f
}
if {$Capitularizar} {
set fichnombre [file tail $f]
regexp -indices {[:alpha:]} $fichnombre indiceLetra
set nunom [string totitle $fichnombre [lindex $indiceLetra 0] end]
file rename -force "[file tail $f]" "$nunom"
} elseif {$minusculizar} {
eval exec mv \"$f\" \"[file dirname $f]/[string tolower [file tail $f]]\"
} elseif [regexp -- "$pat" "[file tail $f]"] {
regsub -all -- "$pat" "[file tail $f]" "$reemp" nunom
puts "'$f' --> '[file dirname $f]/$nunom'"
file rename "$f" "[file dirname $f]/$nunom"
}
}
return 0
}
procDir .
|
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:Hints1 new Hints in the last 24 hoursComments last 2 daysNo new commentsLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.05 seconds |
|