Save file exists?

● ARCHIVED · READ-ONLY
Started by mlogan 5 posts View original ↗
  1.  Hi all! I'm working on a script for my project that will redo how the save system functions.

    I've come across this bit that I think will be useful, but I would love some confirmation on exactly what it is doing. I can gather enough to realize that it is asking if a save file exists. I'm just not 100% certain on what it returns. I would assume true/false? Also, what would be the best way to use this information? Set a variable to this information?

      def self.save_file_exists?
        !Dir.glob('Save*.rvdata2').empty?
      end

    Thanks!
  2. Dir.glob('Save*.rvdata2')Returns a list of files that match the pattern
    If a save file exists, then the list will have at least one item, meaning it's not empty.


    You want to return true when no files were found, which is why it negates it.
  3. Okay, that makes sense. True = empty for that whole bit.

    Now, say I wanted to see if a certain save file existed. Could I say something like:

    if Dir.glob('Save1.rvdata2') = true

    (and then obviously, put what i wanted to happen then)
  4. if Dir.glob('Save01.rvdata2').empty?
    # save file "Save01.rvdata2" does not exist


    end

    Better to just use FileTest.exist?(filename) to avoid the array.
  5. Hmmm. Okay thank you. Off to process this new bit of information into my brain! :D