Check if local file exists?

● ARCHIVED · READ-ONLY
Started by SilverDash 5 posts View original ↗
  1. I couldn't find it anywhere on Google. Only people using Ajax, Microsoft and other variants of Javascript. But how does one check it in RPG Maker? I can't find any info anywhere.

    I also checked the ImageManager but they do it through a listener and the code is not public...

    I need something like

    Code:
    if (FileExists('img/system/example.png')) { alert('yay'); }
  2. By default, the only thing you can check for existance is save files, however you can use a script call to find out.

    Code:
    var fs = require('fs');if(fs.existsSync("index.html")) {  // The file exists, do stuff.} else {  // The file does not exist, do other stuff.}
  3. It works but does not work for relative paths. It only works for full paths like C:/whatever.png. But does not work for for img/system/whatever.png.
  4. You can copy how the StorageManager gets it's path:

    Code:
    var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, "/add your folder name here or leave out");if (path.match(/^\/([A-Z]\:)/)) {  this.path = this._path.slice(1);}path = decodeURIComponent(this._path);
    based off Line 655 StorageManager.localFileDirectoryPath()
  5. Thanks, would have never figured this one out on my own.