Guest16
(Guest)
14 December 2009 14:23
1
Hi,
Can someone please suggest a simple Ruby one-liner to lowercase a
filename (in a directory)? I've perused, with Google, a bunch of good
Ruby one-liner sites, but, I can't find any lowercasing examples.
Thanks a lot,
Peter
···
--
Posted via http://www.ruby-forum.com/ .
Peter Bailey wrote:
Can someone please suggest a simple Ruby one-liner to lowercase a
filename (in a directory)?
Lowercase the *contents* of a file, or its *name* ?
For the contents, this example lifted almost verbatim from "man ruby".
ruby -p -i.bak -e '$_.downcase!' /tmp/junk
To lowercase the names of all files:
Dir["*"].each { |fn| File.rename(fn, fn.downcase) }
Beware that even ruby 1.9 won't lowercase anything other than plain A-Z.
···
--
Posted via http://www.ruby-forum.com/\ .
Guest16
(Guest)
14 December 2009 16:47
3
Thanks, Brian. Yes, it's just filename I want, not content. But, this is
what I get when I try your suggestion:
ruby Dir.glob("*").each { |fn| File.rename(fn, fn.downcase) }
'file' is not recognized as an internal or external command,
operable program or batch file.
Brian Candler wrote:
···
Peter Bailey wrote:
Can someone please suggest a simple Ruby one-liner to lowercase a
filename (in a directory)?
Lowercase the *contents* of a file, or its *name* ?
For the contents, this example lifted almost verbatim from "man ruby".
ruby -p -i.bak -e '$_.downcase!' /tmp/junk
To lowercase the names of all files:
Dir["*"].each { |fn| File.rename(fn, fn.downcase) }
Beware that even ruby 1.9 won't lowercase anything other than plain A-Z.
--
Posted via http://www.ruby-forum.com/\ .
Try
ruby -e 'Dir.glob("*").each { |fn| File.rename(fn, fn.downcase) }'
Otherwise, Dir.glob... will be seen as a shell command, not as ruby code.
Regards,
Florian
···
On Dec 14, 2009, at 1:17 PM, Peter Bailey wrote:
Thanks, Brian. Yes, it's just filename I want, not content. But, this is
what I get when I try your suggestion:
ruby Dir.glob("*").each { |fn| File.rename(fn, fn.downcase) }
'file' is not recognized as an internal or external command,
operable program or batch file.
Guest16
(Guest)
14 December 2009 18:04
5
Still no good. Here's what I get:
ruby -e 'Dir.glob("*.*").each { |fn| File.rename(fn, fn.downcase) }'
'fn' is not recognized as an internal or external command,
operable program or batch file.
E:\Asura-Non\BWDhelp\temp>
Florian Gilcher wrote:
···
On Dec 14, 2009, at 1:17 PM, Peter Bailey wrote:
Thanks, Brian. Yes, it's just filename I want, not content. But,
this is
what I get when I try your suggestion:
ruby Dir.glob("*").each { |fn| File.rename(fn, fn.downcase) }
'file' is not recognized as an internal or external command,
operable program or batch file.
Try
ruby -e 'Dir.glob("*").each { |fn| File.rename(fn, fn.downcase) }'
Otherwise, Dir.glob... will be seen as a shell command, not as ruby
code.
Regards,
Florian
--
Posted via http://www.ruby-forum.com/\ .
W_James
(W. James)
14 December 2009 20:55
6
Do not top-post.
Since you are using the windoze shell, you must learn some things
about the windoze shell. Does that make sense?
In this case, the Ruby code must be enclosed in double quotes.
Try this.
ruby -e "Dir['*'].each{|fn| p fn.downcase }"
···
On Dec 14, 12:04 pm, Peter Bailey <pbai...@bna.com> wrote:
Still no good. Here's what I get:
>ruby -e 'Dir.glob("*.*").each { |fn| File.rename(fn, fn.downcase) }'
'fn' is not recognized as an internal or external command,
operable program or batch file.
E:\Asura-Non\BWDhelp\temp>
Guest16
(Guest)
14 December 2009 21:09
7
w_a_x_man wrote:
Still no good. Here's what I get:
>ruby -e 'Dir.glob("*.*").each { |fn| File.rename(fn, fn.downcase) }'
'fn' is not recognized as an internal or external command,
operable program or batch file.
E:\Asura-Non\BWDhelp\temp>
Do not top-post.
Since you are using the windoze shell, you must learn some things
about the windoze shell. Does that make sense?
In this case, the Ruby code must be enclosed in double quotes.
Try this.
ruby -e "Dir['*'].each{|fn| p fn.downcase }"
Here's what worked. Yours worked, waxman, but I needed a real filename
conversion, not just a print of it.
Thank you all for your help! This is great, simple stuff.
···
On Dec 14, 12:04�pm, Peter Bailey <pbai...@bna.com> wrote:
ruby -e "Dir.glob('*').each{|fn| File.rename(fn, fn.downcase) }"
--
Posted via http://www.ruby-forum.com/\ .
Robert_K1
(Robert K.)
15 December 2009 10:09
8
Note that if you use a directory name in Dir['*'] you need to make
sure the dirname remains unchanged. Then you might rather do
ruby -e 'Dir["path/*"].each {|f| d, p = File.split(f); File.rename(f,
File.join(d, p.downcase))}'
Kind regards
robert
···
2009/12/14 Peter Bailey <pbailey@bna.com>:
w_a_x_man wrote:
On Dec 14, 12:04�pm, Peter Bailey <pbai...@bna.com> wrote:
Still no good. Here's what I get:
>ruby -e 'Dir.glob("*.*").each { |fn| File.rename(fn, fn.downcase) }'
'fn' is not recognized as an internal or external command,
operable program or batch file.
E:\Asura-Non\BWDhelp\temp>
Do not top-post.
Since you are using the windoze shell, you must learn some things
about the windoze shell. Does that make sense?
In this case, the Ruby code must be enclosed in double quotes.
Try this.
ruby -e "Dir['*'].each{|fn| p fn.downcase }"
Here's what worked. Yours worked, waxman, but I needed a real filename
conversion, not just a print of it.
Thank you all for your help! This is great, simple stuff.
ruby -e "Dir.glob('*').each{|fn| File.rename(fn, fn.downcase) }"
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/