I'm looking to commission a script that will check the install directory for a specific file and set a variable that I can later check through a script call.
My instinct says that this wouldn't be too difficult a script to implement. What say you, esteemed coder?
to check for the existance of a file, you don't need a script - it's a single script command that does this. Check the script call topics for that - I don't remember how that command is spelled right now, but I know it has been asked and answered already.
It is. From the help file:
A module containing file test functions.
Module Functions
FileTest.exist?(filename)
Returns true if filename exists.
FileTest.directory?(filename)
Returns true if filename is a directory.
FileTest.file?(filename)
Returns true if filaname is an ordinary file.
FileTest.size(filename)
Returns the size of filename. If filename does not exist, throws an Errno::EXXX exception (most likely Errno::ENOENT).
Tried to run it through a conditional branch, but I'm getting uninitialized constant error. Would I have to run this through a script?
Bear with me. I'm trying to learn 🙂
The command Filetest.exists? requires a string with the name of the file to test, but
Audio
is not a string, it's either a variable or a constant - that's why it doesn't work
Try
Filetest.exists?('Audio')instead, that is a string.
Also, don't forget file extension - 'Audio' is only the correct name if the file has no extension, most files have (like 'Audio.mp3')
I was able to make this work in the Conditional Branch:
File.exists?("C:\\Users\\Owner\\Documents\\Deez Notes.txt")
The reason for the double-backslashes is because a single backslash will be interpreted as a control character along with the next character, leading to an error.
You can also store it in a Switch: $game_switches[76] = File.exists?("C:\\Users\\Owner\\Documents\\Canvas Notes.txt")
Wouldn't have been able to get this right without Andar's and Iavra's advice so big thanks go to them.
The path is only neccessary if the file is stored somewhere other than the main project folder. By default the command checks that folder (where the game.exe had been started in)
You guys rock! I'll try this out later 🙂
EDIT: It all works perfectly. Thank you guys 🙂