Check for Files in the Install Directory

phoenix_rossy

Veteran
Veteran
Joined
Nov 5, 2012
Messages
388
Reaction score
189
First Language
English
Primarily Uses
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?
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,668
First Language
German
Primarily Uses
RMMV
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.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,959
First Language
English
Primarily Uses
RMMV
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).
 
Last edited by a moderator:

phoenix_rossy

Veteran
Veteran
Joined
Nov 5, 2012
Messages
388
Reaction score
189
First Language
English
Primarily Uses
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 :)
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,668
First Language
German
Primarily Uses
RMMV
Tried to run it through a conditional branch, but I'm getting uninitialized constant error.
Please give a screenshot of the exact command you used - that rather sounds as if you have an excess space or some other syntax error that prevents the interpreter from identifying the command.
 

phoenix_rossy

Veteran
Veteran
Joined
Nov 5, 2012
Messages
388
Reaction score
189
First Language
English
Primarily Uses
Ok, now I checked for a different file and got this error:



Here's my conditional branch:



I'm just checking for the existence of the Audio file for experimentation purposes :)
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,668
First Language
German
Primarily Uses
RMMV
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')
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,624
Reaction score
5,104
First Language
English
Primarily Uses
RMVXA
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.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,668
First Language
German
Primarily Uses
RMMV
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)
 

Evgenij

Veteran
Veteran
Joined
Aug 28, 2013
Messages
349
Reaction score
100
First Language
German
Primarily Uses
N/A
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 use forward-slashes:

Code:
File.exists?("C:/Users/Owner/Documents/Deez Notes.txt")
 

phoenix_rossy

Veteran
Veteran
Joined
Nov 5, 2012
Messages
388
Reaction score
189
First Language
English
Primarily Uses
You guys rock! I'll try this out later :)

EDIT: It all works perfectly. Thank you guys :)
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,977
Members
137,563
Latest member
cexojow
Top