User Tools

Site Tools


convert_all_file_name_to_lover

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
convert_all_file_name_to_lover [2009/04/26 02:24]
k2patel
— (current)
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 '​[A-Z]'​ '​[a-z]'​` 
-if [ $lc != $x ]; then 
-mv -i $x $lc 
-fi 
-done 
-</​code>​ 
- 
-<code perl | rename.pl>​ 
-#​!/​usr/​bin/​perl -s 
- 
-if(@ARGV == 0) { 
- opendir PWD, "​.";​ 
- @ARGV = readdir PWD; 
- closedir PWD; 
-} 
- 
-foreach (@ARGV) { 
- # skip if no upper case! 
- next unless /​[[:​upper:​]]/;​ 
- warn "# starting \"​$_\"​\n"​ if $v; # verbose mode 
- next if $_ eq "​.";​ 
- next if $_ eq "​..";​ 
- next if m#​.*/​\.\.?​$#;​ 
- $pathname = $_; 
- warn "# Doing \"​$pathname\"​\n"​ if $v; # verbose mode 
- 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 $_/​$entry\n"​ if $v; # verbose mode 
- unshift @ARGV, "​$_/​$entry";​ 
- } 
- warn "# Redo-ing\n"​ if $v; # verbose mode 
- redo; 
- } 
- if(($dir, $filename) = m!(.*/​)(.*)!) { 
- $_ = $filename; 
- } else { 
- $dir ="";​ 
- } 
- # unicode-friendly way to do equivalent of English [A-Z] -> [a-z] 
- s/​[([:​upper:​])]/​\L$1\E/​g;​ 
- print "mv $pathname $dir$_\n";​ 
- $xx="​xx01";​ 
- unless($n) { 
- if(-e "​${dir}${xx}.$$"​) { 
- # leave it there, increment xx 
- $xx++; 
- if(-e "​${dir}${xx}.$$"​) { 
- die "​\"​${dir}${xx}.$$\"​ no longer safe. Quitting.\n";​ 
- } 
- } 
- print "# moving \"​$pathname\"​ to \"​${dir}${xx}.$$\"​\n"​ if $v; # verbose mode 
- # rename twice in case of case-insensitive file systems 
- rename($pathname,​ "​${dir}${xx}.$$"​) 
- || print "# couldn'​t rename \"​$pathname\"​ to \"​${dir}${xx}.$$\":​ $!\n"; 
- print "# moving \"​${dir}${xx}.$$\"​ to \"​$dir$_\"​\n"​ if $v; # verbose mode 
- rename("​${dir}${xx}.$$",​ "​$dir$_"​) 
- || print "# couldn'​t rename \"​${dir}${xx}.$$\"​ to \"​$dir$_\":​ $!\n"; 
- } 
-} 
- 
-exit(0); 
-</​code>​ 
convert_all_file_name_to_lover.1240712667.txt.gz ยท Last modified: 2020/08/10 02:28 (external edit)