Get the current existing data in a folder

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
I just want to ask if there is a code that allows us to detect the current existing data in a folder. For example, in my img folder I have a folder named samplefolder. Inside the samplefolder folder, I have three files, 'blockA.png', 'blockB.png' and 'blockC.png'. Now, I want to check if those three exist on that folder. I am just wondering if there is a javascript code that would let me kinda check if the folder samplefolder exists and those three images exist.

Thank you in advance.
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
With "normal" JavaScript, that's not possible. You can use the 'fs' module in Node.js (local game), though.


/edit: To clarify: It's possible to detect specific files via Ajax, but you can't just get a list of ALL files in a folder without Node.js.
 
Last edited by a moderator:

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
Is that supported by ES5 / RPG Maker MV in general? I would like to know how to do this in Node.js. I would like to see an example and see what are the limitation it brings. If it is not possible, would there be an alternative that checks if a file is existent inside the game folder, so I can alert the user that such image does not exist.
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
You can find the fs API here: https://nodejs.org/api/fs.html

Node.js only works in local mode (not deployed online, don't know about Android/iOS).

Without Node.js, you can use Ajax like this:

Code:
var request = new XMLHttpRequest();request.open('HEAD', url);   // Path to filerequest.onload = function() { /* file exists */ };request.onerror = function() { /* file doesn't exist */ };request.send();
Note, that this is asynchronous, so you don't know if the file exists, until one of the 2 callbacks gets called. You can change this to a synchronous call, by changing the second line like this:
Code:
request.open('HEAD', url, false);
This will freeze your game, until the request returns and some browsers (like Chrome) log a warning, when doing a synchronous AJAX call, though.
 

jamespedid

Veteran
Veteran
Joined
Jun 10, 2013
Messages
30
Reaction score
3
First Language
English
You can set up a web server for your game (which you should probably do anyway if you ever deploy it); from here, you can pretty much do anything for your game that you can do on a normal web site, since you are serving up content.

If the purpose of this is just to satisfy your laziness, however, you're better off trying to compile everything into a single Javascript file. You can do this pretty easily using a ruby script, for example, or you can look to more sophisticated build libraries.
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
Ohhh this became harder than I thought. I will use Zale's plugin for this. It seems it is a better solution that the one I thought of. I thought there was a manual way for this or a simpler way only for PC developed games (those that are not to be shared online, webserver or an html5 game).
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,045
Members
137,569
Latest member
Shtelsky
Top