Dir

W

wes.monk

Dir.foreach("c:/wes/photos/Bike/*.JPG") {|x| puts "Got#{x}" }

This does not seem to work on my windows xp machine? Should it? I am
trying to get a list of files with the .JPG extension.

If I take the *.JPG out, I get a list of all of the files in that
directory? What am I doing wrong? I just want the .JPG's.

Thanks in advance,

wes
 
K

Kev Jackson

Dir.foreach("c:/wes/photos/Bike/*.JPG") {|x| puts "Got#{x}" }

This does not seem to work on my windows xp machine? Should it? I am
trying to get a list of files with the .JPG extension.

If I take the *.JPG out, I get a list of all of the files in that
directory? What am I doing wrong? I just want the .JPG's.

Thanks in advance,

wes
Dir.foreach("c:/wes/photos/Bike/") { |x| p "got #{x}" if x[x.length-3,
x.length]=='JPG' }

I'm sure there's a better way, but this should do the trick

Kev
 
C

ces.fci

You could do:
Dir["c:/wes/photos/Bike/*.JPG"].each { |x| puts "Got#{x}" }

change JPG to [JPGjpg] to be ignore the case.

c
 
D

David A. Black

Hi --

You could do:
Dir["c:/wes/photos/Bike/*.JPG"].each { |x| puts "Got#{x}" }

change JPG to [JPGjpg] to be ignore the case.

You'd actually need to do:

*.[Jj][Pp][Gg]

With *.[JPGjpg] you'll only match files like file.J and file.p.

You could also do:

*.{jpg,JPG}

if you're sure that those are the only two (i.e., nothing like JpG).


David
 
N

nobuyoshi nakada

Hi,

At Mon, 21 Nov 2005 13:27:10 +0900,
David A. Black wrote in [ruby-talk:166730]:
You could do:
Dir["c:/wes/photos/Bike/*.JPG"].each { |x| puts "Got#{x}" }

Or

Dir.glob("c:/wes/photos/Bike/*.JPG") { |x| puts "Got#{x}" }
 
R

Robert Klemme

nobuyoshi said:
Hi,

At Mon, 21 Nov 2005 13:27:10 +0900,
David A. Black wrote in [ruby-talk:166730]:
You could do:
Dir["c:/wes/photos/Bike/*.JPG"].each { |x| puts "Got#{x}" }

Or

Dir.glob("c:/wes/photos/Bike/*.JPG") { |x| puts "Got#{x}" }

On a Windows box IMHO that should read

Dir.glob("c:\\wes\\photos\\Bike\\*.JPG") { |x| puts "Got#{x}" }

Or - a bit more portable:

Dir[File.join("c:", "wes", "photos", "Bike", "*.jpg")]

Kind regards

robert
 
N

nobuyoshi nakada

Hi,

At Mon, 21 Nov 2005 18:37:24 +0900,
Robert Klemme wrote in [ruby-talk:166758]:
On a Windows box IMHO that should read

Dir.glob("c:\\wes\\photos\\Bike\\*.JPG") { |x| puts "Got#{x}" }

Ruby uses forward-slashes on all platforms.
Or - a bit more portable:

Dir[File.join("c:", "wes", "photos", "Bike", "*.jpg")]

It yields "c:/wes/photos/Bike/*.JPG" even on Windows.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,187
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top