Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
So I am working with Ruby, and...
I have an error "ERRNO::EEXIST, text line 2 ... File exists"
The error occurs if a directory it created (defined in EGGPATH) already exists, which should work in itself because of "unless File.exist?(EGGPATH)"
While what I'm trying to do is:
def cyhm   #file text
  Dir.mkdir(EGGPATH) unless File.exist?(EGGPATH)
  File.open(EGGPATH + "/CAN YOU HEAR ME.txt", "w+") do |f|
    f.write("text")
  end
end
def cyhm_pt2
  Dir.mkdir(EGGPATH) unless File.exist?(EGGPATH)
  if File.exists?(EGGPATH + "/CAN YOU HEAR ME.txt") == false
    cyhm
  end
  File.open(EGGPATH + "/CAN YOU HEAR ME.txt", "a+") do |f|
    f.write("text2")
  end
end

While EGGPATH is defined here, in the other file:
TXTLIST = ["Ą", "ą", "Ć", "ć", "Ę", "ę", "Ł", "ł", "Ń", "ń", "Ó", "ó", "Ś", "ś", "Ź", "ź", "Ż", "ż"] #file randomtxt
EGGPAT = TXTLIST[rand(TXTLIST.size)] + TXTLIST[rand(TXTLIST.size)] + TXTLIST[rand(TXTLIST.size)] + TXTLIST[rand(TXTLIST.size)] + TXTLIST[rand(TXTLIST.size)] + TXTLIST[rand(TXTLIST.size)] + TXTLIST[rand(TXTLIST.size)] + TXTLIST[rand(TXTLIST.size)] + TXTLIST[rand(TXTLIST.size)] + TXTLIST[rand(TXTLIST.size)] + TXTLIST[rand(TXTLIST.size)]
if File.exists?(SAVEPATH + "\\MODAR\\eseggdir.es") == false
  File.open(SAVEPATH + "\\MODAR\\eseggdir.es", "w+") do |f|
    f.write(EGGPAT)
  end
end
EGGPATH = File.read(SAVEPATH + "\\MODAR\\eseggdir.es")


Also, don't tell me to switch to a newer version of Ruby, cause I'm working with RPGXP, and I don't want to change it anytime soon...

What I have tried:

I haven't tried anything, sorry, because as far as I know (which isn't very much) everything should work fine.
Posted
Updated 14-Dec-18 23:59pm
v2
Comments
Richard MacCutchan 12-Dec-18 16:08pm    
"as far as I know everything should work fine."
I am afraid you have a lot to learn.
Akin0 13-Dec-18 8:00am    
Yes, I do

You most likely should use Dir.exist, not File.exist to check for a directory.
 
Share this answer
 
Comments
Akin0 13-Dec-18 8:10am    
"Undefined method "exist?" for Dir:Class"
Richard MacCutchan 13-Dec-18 8:22am    
That method is in Class: Dir (Ruby 2.5.1)[^]. So, I guess you have to find some other way of testing if the directory exists.
Akin0 13-Dec-18 8:28am    
Yeah, but File.exist always worked on directories...
Richard MacCutchan 13-Dec-18 9:35am    
Well it appears not to work in this case. I guess you need to do some more debugging to find out exactly what is happening.
Okay, so the problem actually was -- Ruby cannot stand checking the names that have other characters than English alphabet in itself. That was actually pretty hard to come up with, but I guess this is the solution.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900