Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recursively convert all folder and file names to lower-case or upper-case

Tags:

ruby

I have a folder structure like follows.

-FOO
  -BAG
     Rose.TXT
-BAR
    JaCk.txt

I need the following output.

-foo
  -bag
    rose.txt
-bar
    jack.txt
like image 236
Mr. Black Avatar asked Dec 05 '25 16:12

Mr. Black


2 Answers

I realize you want ruby code, but I present to you a one liner to run in your shell:

for i in `find * -depth`; do (mv $i `echo $i|tr [:upper:] [:lower:]`); done

as found here: http://ubuntuforums.org/showthread.php?t=244738

Run it once, and it should do the trick.

Update

Ruby Code:

Dir.glob("./**/*").each do |file|
  File.rename(file, file.downcase) #or upcase if you want to convert to uppercase
end
like image 151
Mike Lewis Avatar answered Dec 08 '25 06:12

Mike Lewis


Dir["**/*"].each {|f| File.rename(f, f.downcase)}
like image 40
Wes Avatar answered Dec 08 '25 06:12

Wes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!