From: "J.Hawkesworth" Date: 2002-11-13T01:17:40+09:00 Subject: [FAQ] was RE: How do I get a '\'? Gavin Sinclair requested that I sent this. I hope it makes sense, is true, and is of use. Q: I'm working with files and directories on Windows. How do I get a '\' (the file separator)? Whatever I try irb or 'p' shows me '\\'. A: '\\' really does produce '\' when your code is run. Both p and irb use 'inspect', which returns a "displayable" representation of a string that can be re-evalled back into ruby. [Simon Cozens] Austin Ziegler notes that you can get away with using forward slashes ('/') if you're only using Ruby file operations; only when you're doing Windows-based file operations do you need to do: foo.gsub('/', '\\') A (pointless) example: Dir.entries("C:ruby/bin") or Dir.entries("C:/ruby/bin") works under Windows, but if you wanted to use the Windows command 'DIR' you would have to write `Dir C:ruby\\bin` While I've been typing, another possible FAQ entry occurs to me: Q: How do I get a recursive list of all the files under a directory and its subdirectories? Dir.entries only gets me the files in the specified directory. Why isn't there a recursive version? A: 'find' will probably do what you want. The code below fills 'dirs' with directories and 'files' with filenames for a given directory require 'find' dirs = [] files = [] Find.find(directory) {|f| if FileTest.directory?(f) dirs.push(f) else files.push(f) end } Please add to/edit/make corrections if needed. All the best, Jon _____________________________________________________________________ This message has been checked for all known viruses by Star Internet delivered through the MessageLabs Virus Control Centre. For further information visit http://www.star.net.uk/stats.asp _____________________________________________________________________ Any views or personal opinions expressed within this email may not be those of Talis Information Ltd. The content of this email message and any files that may be attached are confidential, and for the usage of the intended recipient only. If you are not the intended recipient, then please return this message to the sender and delete it. Any use of this e-mail by an unauthorised recipient is prohibited.