0

in my ruby-code I want to save some contents in a file. This file should be saved at a directory with whitespace in its path.

If the directory doesn't exist I do: Dir.mkdir(directory_name) unless File.exists?(directory_name)

This works in a directory without whitespace in path.

I put the filepath in "" and in '' but then the following error occured:

C:/Program Files (x86)/MantisScraper/mantis_final.rb:378:in `initialize': Invalid argument - "C:\Program Files (x86)\MantisScraper\testfiles\"test_cases_5_5_0.xml (Errno::EINVAL)
        from C:/Program Files (x86)/MantisScraper/mantis_final.rb:378:in `new'
        from C:/Program Files (x86)/MantisScraper/mantis_final.rb:378:in `writeX
ML'
        from C:/Program Files (x86)/MantisScraper/mantis_final.rb:418:in `<main>

I also tried directory_name.gsub(" ", "\s")

nothing helped...

Edit:

Batch-File:

set OUTPATH=C:\Program Files (x86)\MantisScraper\testfiles\
ruby "C:\Program Files (x86)\MantisScraper\mantis_final.rb"

Ruby-File:

Dir.mkdir(ENV['OUTPATH']) unless File.exists?(ENV['OUTPATH'])   
filePath << ENV['OUTPATH'] << "test_cases.xml"  
datei = File.new(filePath, "w")

The programm runs, but wants to write the xml-file in the directory C:\Program

Error-Message: "C:\Program" konnte nicht gefunden werden. Stellen sie sicher, dass Sie den Namen richtig eingegeben haben und wiederholen sie den Vorgang.

user2244536
  • 67
  • 2
  • 10
  • 2
    You have to remember that your not in the shell. So, you don't need to wrap the directory, or filepath in quotes. – Linuxios Apr 19 '13 at 12:59
  • Yes I only tried it with the quotes. But it doenst work without them too. – user2244536 Apr 19 '13 at 13:09
  • Are you sure? If the contents of the string is `C:\Program Files (x86)\MantisScraper\testfiles\test_cases_5_5_0.xml`? – Linuxios Apr 19 '13 at 13:10
  • I open my ruby-script with a batch file. There i have set OUTPATH=C:\Program Files (x86)\MantisScraper\testfiles\ The full OUTPATH-Variable is in my code. I tried this by puts ENV['OUTPATH'] – user2244536 Apr 19 '13 at 13:19
  • What do you mean, the full OUTPATH is in your code? – Linuxios Apr 19 '13 at 13:19
  • I mean that when i do puts ENV['OUTPATH'] the full directory-path is displayed. And not only C:\Program – user2244536 Apr 19 '13 at 13:22
  • In that case, instead of how you're using the path currently, try this: `ENV['OUTPATH']+'\filename.xml'`. No changes, no gsubs, nothing. – Linuxios Apr 19 '13 at 13:24
  • 1
    Can you post a short program that we can run that reproduces the problem? – Catnapper Apr 19 '13 at 13:56
  • Code examples can be marked with 4 leading spaces. See also http://stackoverflow.com/editing-help – knut Apr 19 '13 at 14:37
  • In your actual error message, the filename is _"test_cases_5_5_0.xml_ (including an invalid `"`) - can you check this and provide a code example with your error. – knut Apr 19 '13 at 14:39
  • Is ita problem with pathes with a space or is it a specific `program`-folder? Perhaps it is a problem with the virtual store of windows. Are you sure the file exists at the location you test? See http://stackoverflow.com/a/6193802/676874 for an explanation what problems the virtual store can create. – knut Apr 19 '13 at 15:29
  • Please post your code,you are using and error marked line number also point there. which make help us to give you the solution. – Arup Rakshit Apr 19 '13 at 15:32

0 Answers0