Check for Files in the Install Directory

Discussion in 'RGSS3 Script Requests' started by phoenix_rossy, May 8, 2015.

    Tags:
  1. phoenix_rossy

    phoenix_rossy Veteran Veteran

    Messages:
    388
    Likes Received:
    189
    First Language:
    English
    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?
     
    #1
  2. Andar

    Andar Veteran Veteran

    Messages:
    28,418
    Likes Received:
    6,485
    Location:
    Germany
    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.
     
    #2
  3. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    856
    First Language:
    German
    #3
    Wavelength likes this.
  4. phoenix_rossy

    phoenix_rossy Veteran Veteran

    Messages:
    388
    Likes Received:
    189
    First Language:
    English
    Thanks guys!
     
    #4
  5. Trihan

    Trihan Speedy Scripter Veteran

    Messages:
    1,483
    Likes Received:
    978
    Location:
    Buckie, Scotland
    First Language:
    English
    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: May 8, 2015
    #5
    Zeriab likes this.
  6. phoenix_rossy

    phoenix_rossy Veteran Veteran

    Messages:
    388
    Likes Received:
    189
    First Language:
    English
    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 :)
     
    #6
  7. Andar

    Andar Veteran Veteran

    Messages:
    28,418
    Likes Received:
    6,485
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    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.
     
    #7
  8. phoenix_rossy

    phoenix_rossy Veteran Veteran

    Messages:
    388
    Likes Received:
    189
    First Language:
    English
    Ok, now I checked for a different file and got this error:

    [​IMG]

    Here's my conditional branch:

    [​IMG]

    I'm just checking for the existence of the Audio file for experimentation purposes :)
     
    #8
  9. Andar

    Andar Veteran Veteran

    Messages:
    28,418
    Likes Received:
    6,485
    Location:
    Germany
    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')
     
    #9
    Wavelength likes this.
  10. Wavelength

    Wavelength Pre-Merge Boot Moderator

    Messages:
    4,378
    Likes Received:
    3,654
    Location:
    Florida, USA
    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.
     
    #10
  11. Andar

    Andar Veteran Veteran

    Messages:
    28,418
    Likes Received:
    6,485
    Location:
    Germany
    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)
     
    #11
  12. Evgenij

    Evgenij Veteran Veteran

    Messages:
    349
    Likes Received:
    100
    First Language:
    German
    Primarily Uses:
    N/A
    You can also use forward-slashes:

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

    phoenix_rossy Veteran Veteran

    Messages:
    388
    Likes Received:
    189
    First Language:
    English
    You guys rock! I'll try this out later :)

    EDIT: It all works perfectly. Thank you guys :)
     
    Last edited by a moderator: May 12, 2015
    #13

Share This Page