I have one of those USB memory stick things and I’ve written a little
ruby script to back up the contents of the memory stick to my hard disk.
However it is ugly and relies on nasty dos commands like xcopy. I’m
trying to write a new version that recurses through the directories on
the memory stick but I can’t find a way to get ruby to produce a single
‘’ character (which I need for specifiying subdirectories).
irb(main):041:0> p “\”
“\”
nil
irb(main):042:0> p 92.chr
“\”
nil
but
irb(main):043:0> p 91.chr
“[”
nil
irb(main):044:0> p 93.chr
“]”
nil
interestingly I also get:
irb(main):045:0> p File::Separator
“/”
nil
I’ve tried the same code snippets in a script and get the same results.
I’m using ruby 1.66 Pragmatic Programmers version on Windows 2000.
Any bright ideas/wisdom gratefully appreciated.
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
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.
the memory stick but I can’t find a way to get ruby to produce a single
'' character (which I need for specifiying subdirectories).
irb(main):041:0> p “\”
“\”
You’re being bitten by the fact that p uses inspect, and
String.inspect gives you a “displayable” representation of a string
that can be re-evalled back into ruby.
“\” does what you want:
% ruby -e ‘print “\”’
\
···
–
“If you want to travel around the world and be invited to speak at a lot
of different places, just write a Unix operating system.”
(By Linus Torvalds)
This is the String \ but irb calls inspect before printing it. That’s
why the \ is escaped again. You can run irb --noinspect if you don’t
like that. If you want to have the character \ you could use ?\ or
“\”[0].
···
On 2002-10-30 19:47:52 +0900, J.Hawkesworth wrote:
irb(main):041:0> p “\”
“\”
nil
irb(main):042:0> p 92.chr
“\”
nil
–
Democracy is two wolves and a sheep trying to decide what’s for dinner.
You should probably upgrade to the latest Ruby-win32 (listed at http://www.rubygarden.org/ruby?WindowsInstaller), so that you’re
dealing with the latest bugfixes. Note 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('/', '\\')
The attached code handles what you’re after.
-austin
– Austin Ziegler, austin@halostatue.ca on 2002.10.30 at 10.42.21
On Wed, 30 Oct 2002 19:47:52 +0900, J.Hawkesworth wrote:
Hi,
I have one of those USB memory stick things and I’ve written a
little ruby script to back up the contents of the memory stick to
my hard disk. However it is ugly and relies on nasty dos commands
like xcopy. I’m trying to write a new version that recurses
through the directories on the memory stick but I can’t find a way
to get ruby to produce a single '' character (which I need for
specifiying subdirectories).
I’ve tried the same code snippets in a script and get the same
results. I’m using ruby 1.66 Pragmatic Programmers version on
Windows 2000. Any bright ideas/wisdom gratefully appreciated.