'Couldn't find file' even though the directory is literally the file's location???

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Nightmarecool2
Newbie
Posts: 12
Joined: Thu Aug 11, 2022 5:38 pm
Contact:

'Couldn't find file' even though the directory is literally the file's location???

#1 Post by Nightmarecool2 »

Hello, there. Basically what I was trying to do was copy a file from the folder: 'notepad' (That file being: 'to_niko.txt'). Then copy and paste it to another directory. So, something like DDLC where it looks like the file was put there by someone from the game. However, when I tried testing it, I came across this troubleshoot message and along with that troubleshoot message everytime I open the txt folder it's empty. Sometimes the file itself is copied to desired directory but the contents are empty.

For reference the code that's causing this error is this:

Code: Select all

                python:
                    try: renpy.file(config.basedir + "/game/notepad/to_niko.txt")
                    except: open(config.basedir + "/game/notepad/to_niko.txt", "wb").write(renpy.file("/notepad/to_niko.txt").read())
Here is the troubleshoot message:

Code: Select all


I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 6983, in script
    python:
  File "game/script.rpy", line 6985, in <module>
    except: open(config.basedir + "/game/notepad/to_niko.txt", "wb").write(renpy.file("/notepad/to_niko.txt").read())
OSError: Couldn't find file 'notepad/to_niko.txt'.

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 6983, in script
    python:
  File "C:\Users\My Laptop\Desktop\ETOT_Current_Progress\renpy\ast.py", line 1138, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\My Laptop\Desktop\ETOT_Current_Progress\renpy\python.py", line 1122, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "game/script.rpy", line 6985, in <module>
    except: open(config.basedir + "/game/notepad/to_niko.txt", "wb").write(renpy.file("/notepad/to_niko.txt").read())
  File "C:\Users\My Laptop\Desktop\ETOT_Current_Progress\renpy\exports.py", line 2607, in file
    return open_file(fn, encoding=encoding)
  File "C:\Users\My Laptop\Desktop\ETOT_Current_Progress\renpy\exports.py", line 2589, in open_file
    rv = renpy.loader.load(fn, directory=directory)
  File "C:\Users\My Laptop\Desktop\ETOT_Current_Progress\renpy\loader.py", line 833, in load
    raise IOError("Couldn't find file '%s'." % name)
OSError: Couldn't find file 'notepad/to_niko.txt'.

Windows-10-10.0.22621 AMD64
Ren'Py 8.1.1.23060707
The Eerie Town of Tora 1.0
Mon Nov 20 20:49:06 2023
Also, if there is an alternative way for what I am trying to do(That works for other computers) then that is also appreciated.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2438
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: 'Couldn't find file' even though the directory is literally the file's location???

#2 Post by Ocelot »

open(config.basedir + "/game/notepad/to_niko.txt", "wb").write(renpy.file("/notepad/to_niko.txt").read())
You are trying to open file already opened and locked. No surprise that you get an error.
Try to write into different file, not the one you will read from.
< < insert Rick Cook quote here > >

Nightmarecool2
Newbie
Posts: 12
Joined: Thu Aug 11, 2022 5:38 pm
Contact:

Re: 'Couldn't find file' even though the directory is literally the file's location???

#3 Post by Nightmarecool2 »

Thank you for the response, can you please provide an example?

How would the correct syntax be?

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2438
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: 'Couldn't find file' even though the directory is literally the file's location???

#4 Post by Ocelot »

The syntax is correct. You just need to read from some other file and not the one you are trying to write.
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot], decocloud