From: Luis Lavena Date: 2010-12-13T05:25:19+09:00 Subject: Re: Chdir on Windows - beginner doubt On Dec 12, 4:39 pm, "Marcelo S." wrote: > Folks, > Hello Marcelo, > Hi, this is my first post here. Tried to search the forum for a specific > answer, but didn't find it. I'm not a programmer, just a curious. Got > Chris Pine's "Learning to Program", and I'm going through all the > exercises. I'm in the YAML chapter now, and I'm trying to adapt the > picture-renaming exercise. > > Somehow, though, my computer doesn't do the task. I'm not sure if the > problem is in Chdir or in another instruction (or even in the addresses > I gave). > > I use Windows Vista. These are the first two lines, where I use Dir: > > Dir.chdir ('D:\\Fotos') > pic_names=Dir['C:\\Users\\Marcelo\\Pictures\\*.{JPG.jpg}'] > > The double inverted slashes were put after I read something about this > being the way Ruby gets the syntax in Windows. > > It says "Downloading 0 files: " Download 0 files is part of the script, correct? > And nothing else happens. Perhaps the script is expecting a list of files and got none. > > What did I do wrong? > Nothing you did wrong, but Dir globing is expecting forward slashes instead of backslashes. Try, in a IRB prompt: irb(main):001:0> Dir["C:\\Users\\Luis\\Pictures\\Avatars\\*.png"] => [] Got zero results, now with forward slashes: irb(main):003:0> Dir["C:/Users/Luis/Pictures/Avatars/*.png"] => ["C:/Users/Luis/Pictures/Avatars/IMG_0231.png", "C:/Users/Luis/ Pictures/Avatars/IMG_0231_CROP (Custom).png", "C:/Users/Luis/Pictures/ Avatars/IMG_0231_CROP.png", "C:/Users/Luis/Pictures/Avatars/Logo Multimedia systems.png"] Got some results. If the path you entered was from the command line or from a input, then you can try do File.expand_path to transform the double backslashes to forward slashes. Hope that helps and welcome to Ruby! -- Luis Lavena