Please find the code which I ran from the IRB terminal:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\rakshiar>irb
irb(main):001:0> src = 'E:\WIPData\Ruby\Scripts\TaxDocumentDownload'
=> "E:\\WIPData\\Ruby\\Scripts\\TaxDocumentDownload"
irb(main):002:0> dest = 'E:\WIPData\Ruby\Scripts'
=> "E:\\WIPData\\Ruby\\Scripts"
irb(main):003:0> dest<<'H00371101'
=> "E:\\WIPData\\Ruby\\ScriptsH00371101"
irb(main):004:0>
Why here such \\ is coming? How to fix that?
When i am running the same part from the script getting the below warnings:
CODE
src = 'E:\WIPData\Ruby\Scripts\TaxDocumentDownload'
dest = 'E:\WIPData\Ruby\Scripts'
dest<<'H00371101'
FileUtils.copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
Warning:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\rakshiar>cd..
C:\Documents and Settings>cd..
C:\>e:
E:\>cd E:\WIPData\Ruby\Scripts
E:\WIPData\Ruby\Scripts>downloadv1.rb
C:/Ruby193/lib/ruby/1.9.1/FileUtils.rb:93: warning: already initialized constant
OPT_TABLE
C:/Ruby193/lib/ruby/1.9.1/FileUtils.rb:1268: warning: already initialized consta
nt S_IF_DOOR
C:/Ruby193/lib/ruby/1.9.1/FileUtils.rb:1496: warning: already initialized consta
nt DIRECTORY_TERM
C:/Ruby193/lib/ruby/1.9.1/FileUtils.rb:1500: warning: already initialized consta
nt SYSCASE
C:/Ruby193/lib/ruby/1.9.1/FileUtils.rb:1619: warning: already initialized consta
nt LOW_METHODS
C:/Ruby193/lib/ruby/1.9.1/FileUtils.rb:1625: warning: already initialized consta
nt METHODS
Could you please say why such warnings are coming?
When try the below from the IRB again different output:
C:\Documents and Settings\rakshiar>irb
irb(main):001:0> src = "E:\WIPData\Ruby\Scripts\TaxDocumentDownload"
=> "E:WIPDataRubyScriptsTaxDocumentDownload"
irb(main):002:0> est = "E:\WIPData\Ruby\Scripts"
=> "E:WIPDataRubyScripts"
irb(main):003:0> est<<"H00371101"
=> "E:WIPDataRubyScriptsH00371101"
irb(main):004:0> est<<"H00371101"
EDIT:
ERROR
E:\WIPData\Ruby\Scripts>downloadv1.rb
E:/WIPData/Ruby/Scripts/downloadv1.rb:87: syntax error, unexpected tCONSTANT, ex
pecting $end
dest<<"H00371101"
^
From the script code part:
src = "E:\WIPData\Ruby\Scripts\TaxDocumentDownload"
dest = "E:\WIPData\Ruby\Scripts\"
dest<<"H00371101"
FileUtils.copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
I want that src and dest directory as the real directory path. How to get that?
Thanks.
Ruby has, broadly speaking, two types of strings. In a double-quoted string, backslashes “escape” characters – a backslash followed by another letter produces a special character. For example,
"\n"gives you a newline. Inside single-quoted strings, the backslash doesn’t escape characters –'\n'is just a backslash followed by the lettern. (Actually this isn’t 100% true, the exception is'\''which is a single quote – otherwise there would be no way to embed a single quote in a single-quoted string.That’s why your single-quoted
src = 'E:\WIPData\Ruby\Scripts\TaxDocumentDownload'will work, and double-quotedsrc = "E:\WIPData\Ruby\Scripts\TaxDocumentDownload"will not.The double-backslashes are printed there because
irbusesinspecton the resulting output, which returns the string in double-quoted form (with special characters escaped):They’re not really in the string, as you can see with
puts:The error you have is because of using a double-quoted string, the backslashes are treated as escape characters, so your string is unterminated:
is parsed the same as
which is a syntax error.
You should go and read about the difference between single- and double-quoted strings. Here’s one resource.
A quick google suggests that you might be doing
require 'FileUtils'notrequire 'fileutils'? This post said that the same warnings disappeared once they changed to the latter. It’s because Windows’ file system is not case-sensitive – to Ruby, FileUtils.rb and fileutils.rb are two different files, but to Windows, they’re the same.