convert_all_file_name_to_lover
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| convert_all_file_name_to_lover [2009/04/26 02:24] – k2patel | convert_all_file_name_to_lover [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Convert all file name to lovercase ====== | ||
| - | **Note Does not work with spaces | ||
| - | |||
| - | <code bash | lowerit> | ||
| - | #!/bin/sh | ||
| - | # lowerit | ||
| - | # convert all file names in the current directory to lower case | ||
| - | # only operates on plain files--does not change the name of directories | ||
| - | # will ask for verification before overwriting an existing file | ||
| - | for x in `ls` | ||
| - | do | ||
| - | if [ ! -f $x ]; then | ||
| - | continue | ||
| - | fi | ||
| - | lc=`echo $x | tr ' | ||
| - | if [ $lc != $x ]; then | ||
| - | mv -i $x $lc | ||
| - | fi | ||
| - | done | ||
| - | </ | ||
| - | |||
| - | <code perl | rename.pl> | ||
| - | # | ||
| - | |||
| - | if(@ARGV == 0) { | ||
| - | opendir PWD, " | ||
| - | @ARGV = readdir PWD; | ||
| - | closedir PWD; | ||
| - | } | ||
| - | |||
| - | foreach (@ARGV) { | ||
| - | # skip if no upper case! | ||
| - | next unless / | ||
| - | warn "# starting \" | ||
| - | next if $_ eq " | ||
| - | next if $_ eq " | ||
| - | next if m# | ||
| - | $pathname = $_; | ||
| - | warn "# Doing \" | ||
| - | if($r && -d $_ && /^[^\/]+$/) { | ||
| - | print "# visiting directory $_\n"; | ||
| - | opendir DIR, $_; | ||
| - | my @dir = readdir DIR; | ||
| - | closedir DIR; | ||
| - | foreach my $entry (@dir) { | ||
| - | next if $entry eq " | ||
| - | next if $entry eq " | ||
| - | warn "# Adding $_/ | ||
| - | unshift @ARGV, " | ||
| - | } | ||
| - | warn "# Redo-ing\n" | ||
| - | redo; | ||
| - | } | ||
| - | if(($dir, $filename) = m!(.*/ | ||
| - | $_ = $filename; | ||
| - | } else { | ||
| - | $dir =""; | ||
| - | } | ||
| - | # unicode-friendly way to do equivalent of English [A-Z] -> [a-z] | ||
| - | s/ | ||
| - | print "mv $pathname $dir$_\n"; | ||
| - | $xx=" | ||
| - | unless($n) { | ||
| - | if(-e " | ||
| - | # leave it there, increment xx | ||
| - | $xx++; | ||
| - | if(-e " | ||
| - | die " | ||
| - | } | ||
| - | } | ||
| - | print "# moving \" | ||
| - | # rename twice in case of case-insensitive file systems | ||
| - | rename($pathname, | ||
| - | || print "# couldn' | ||
| - | print "# moving \" | ||
| - | rename(" | ||
| - | || print "# couldn' | ||
| - | } | ||
| - | } | ||
| - | |||
| - | exit(0); | ||
| - | </ | ||
convert_all_file_name_to_lover.1240712667.txt.gz · Last modified: 2020/08/10 02:28 (external edit)
