On 9/27/07, dtown22 / gmail.com <dtown22 / gmail.com> wrote: > Hi, > > I am a bit of a ruby newbie, and i cant figure out this problem. I am > recursively searching through some directories, and when i find the > one i want, i try to pass it to an external process, through 'system' > but the forward slashes screw things up. > > i tried replacing the forward slashes through gsub, but i end up with > 2 slashes. for example, if i am trying to 'dir' a path, this ends up > being sent through system: > > dir c:\\myStartDir/currentDir #obviously this wont work, so i tried > using gsub, and i get this > > dir c:\\myStartDir\\currentDir #and 'dir' complains it cant find the > directory. > > my code looks something like this > > dirPath = File.dirname(path).gsub('/', "\\") > system("dir " + dirPath) > > path is determined using Find.find(c:\\myStartDir) > > any help is greatly appreciated. Thanks! I use path.gsub(File::SEPARATOR, File::ALT_SEPARATOR) for the conversion. But I don't think that's your problem. How did you print those paths? For me Find.find("c:\\ruby") {|f| puts f.gsub('/', "\\")} works fine. Can you replace system("dir " + dirPath ) with puts ("dir " + dirPath) to see the output? If you use p to print values, it will escape special chars, therefore slashes will be doubled. The same in irb. Or, replace "dir " with "echo dir " and see the result. I guess you should test dirPath whether it's a directory. () system("dir " + dirPath) if File.directory? dirPath or better still, if File.directory? path dirPath = File.dirname(path).gsub('/', "\\") system("dir " + dirPath) end Jano