File.open(“test.txt”) or File.open(?) created once an accessibel file.
After deleting teh file the same command provided me with:
Error: #<Errno::ENOENT: No such file or directory @ rb_sysopen - test.txt>
Deleting temp files and repairing the SU exe did not make File.new work.
What to do?
With kindest regards, MM
However, I’m not sure how it will work on such a Cloud based OS as yours, I guess should be similar…
Are you using relative file paths like in this example? Or are you using absolute paths. If you’re not using absolute paths, can you try that first?
Error: #<Errno::ENOENT: No such file or directory @ rb_sysopen - C:\Users\xxx\desktop\logtst.txt>
Error: #<Errno::ENOENT: No such file or directory @ rb_sysopen - \logtst.txt>
The File.open or .new command is entered and executed via the Ruby console.
In case I create a file with the same, or another name directly via windows I am able to write and change the file by File.open() in the console. The path to the file is found and the file gets changed.
Just creating the file from the console or an .rb is not possible.
Thank you for efforts & responding.
Your syntax is wrong on Windows,
\ >> /
(Even can be Better to use File #join )
Then you need to add a
mode parameter as well. ( https://ruby-doc.org/core-2.7.2/File.html#method-c-new )
Eg. this should work:
file = File.new("c:/Users/xxxx/Desktop/logtst.txt", "w")
To expand on @dezmo’s reply, in Ruby and many other coding languages the backslash character \ is an escape which gives the next character in a string special handling. For example \t denotes a tab character. Such languages use the forward slash as the path separator. Use of backslash in file paths on Windows was an ill-advised choice made way back in the MSDOS days, probably just to be different.
You can avoid the problem by doubling the backslash, but that’s a nuisance!
file = File.new(“c:/Users/xxx/Desktop/logtst.txt”, “w”);file.puts(“something”);file.close
Did work!!! thnks
thought I tried it from the beginning. Apparntly not!
You are welcome!
I would also recommend to learn how to post your code correctly in the forum:
[How to] Post correctly formatted and colorized code on the forum? - Developers - SketchUp Community
Have a nice day!
I’d recommend using block variant of this, as that ensures the file is closed in case there should be any errors in between.
And for simple reading and writing you have
… but only in a double quoted string. The sample code was using a single quoted string so a backslash would be okay.
I think it was the lack of a mode parameter, myself.
You are likely right about the mode. But by the time the snippet got down to where I looked, it was in double quotes and I didn’t backtrack to notice the original single quotes.
Just for the sake of accuracy!
The original poster “sample codes” anyway used the wrong character for both kind of quotes, Magnified:
While the proper double and single quotes are looks like this:
I was referring to the 4th post.
Also it is not the user using the wrong quote characters, it’s the forum software that is replacing them with “smart quotes”. The poster can overcome this by delimiting code snippets with backquote characters. Ie …
Putting the first line of that post between backquote characters, the forum does not convert the wrong character of single quotes to the right one:
However the “error” is much more visible,
I guess the poster using the wrong editor for coding…