Mark91

Veteran
Veteran
Joined
May 19, 2017
Messages
160
Reaction score
20
First Language
Italian
Primarily Uses
RMMV
Hi,
Is there a script able to search if a file exists no matter where in the pc?
I always have to specify a path, but what about I don't already know where the file I search is located?

Code:
◆Script:var os = require("os")
:      :$gameVariables.setValue(281, os.homedir())
◆Script:var x = $gameVariables.value(281)
:      :var xArr = phrase.split("\\")
:      :$gameVariables.setValue(288, (xArr[0]))

◆If:Script:require('fs').existsSync($gameVariables.value(288)+"/text.txt")
  ◆Commento:File exists
  :        :End
  ◆
:Else

Using the code above I can search if "text.txt" exists in C:/.
Using some more variables and a loop I menaged to search in every C: folders, but then?
Every C: folder has its own subfolder, how can I search even there?
 

eomereolsson

Veteran
Veteran
Joined
Sep 29, 2021
Messages
434
Reaction score
358
First Language
German
Primarily Uses
RMMV
While it is certainly possible to scan the whole PC for files (and I am sure there exists some way to do this in javascript) I would like to ask you why you are doing that. A program scanning the whole PC will (apart from ethical concerns) potentially trigger some malware protection. So I believe an approach that is more narrowly targeted at what you are actually trying to achieve will better suit you.
 

Mark91

Veteran
Veteran
Joined
May 19, 2017
Messages
160
Reaction score
20
First Language
Italian
Primarily Uses
RMMV
While it is certainly possible to scan the whole PC for files (and I am sure there exists some way to do this in javascript) I would like to ask you why you are doing that. A program scanning the whole PC will (apart from ethical concerns) potentially trigger some malware protection. So I believe an approach that is more narrowly targeted at what you are actually trying to achieve will better suit you.
Hi, thank you for your reply.
I'm just experimenting, for example enabling/disabling some in-game options through the reading of a .txt file.
Since I could possibly extend this idea (idk right now, maybe some database files?) I'm interested in the ability to check for a file wherever I wanna put it.
Maybe returning its path location.
 

eomereolsson

Veteran
Veteran
Joined
Sep 29, 2021
Messages
434
Reaction score
358
First Language
German
Primarily Uses
RMMV
If you are just experimenting to learn, then I recommend googling something like "recursively search for file javascript" you are bound to find something useful, especially on stackoverflow.
However for the use-cases you described a search of the whole computer (and mind you, some computers have more than a C: drive or no drive in the windows-sense of the word at all) would not be the best approach.
For reading a config or database file just take a look at the way the default engine does that. It does not need to scan the whole pc. It knows "from the point I am at there must be a data subfolder containimg the database files. In the same folder I am currently in there must be the config file".
If the whole PC was searched how would there be a guarantee that the found files are actually meant for your programm and not for something else?
 
Last edited:

ShadowDragon

Realist
Veteran
Joined
Oct 8, 2018
Messages
6,289
Reaction score
2,461
First Language
Dutch
Primarily Uses
RMMV
there is also a side-effect on the text.txt file,

for example, credits.txt is what you want to search for, and it exist
over 10 folders, how do you know how it would take this apart from
any other txt files if they share the same name?

there can be conflicts, so it is not really recommend to search the
entire system for a file.

this can and will break the mechanic you want to build or experiment.
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
5,459
Reaction score
3,536
First Language
English
Primarily Uses
RMMV
I'm just experimenting, for example enabling/disabling some in-game options through the reading of a .txt file.
Experimenting and learning how to do things is fine. But, as mentioned above, it doesn't really make sense to say "I'm going to have a text file with options for my game" and also say "I don't know where that file will be."

Since I could possibly extend this idea (idk right now, maybe some database files?) I'm interested in the ability to check for a file wherever I wanna put it.
Again...if you've put the file there, then I don't see how you wouldn't already know where you put it.

It's cool to learn how to do stuff in JavaScript just to learn, but as far as your game goes, saying "You can have an options file/database and it goes in any random location on your computer" is just ridiculous. That's not how any professional software does it.

As far as your abstract learning goes, I get a bunch of articles when I Google "JavaScript search directory" and other such terms.
 

Latest Threads

Latest Posts

Latest Profile Posts


Clarn Hold
(No storylines)
There was a tutorial on how to draw anime eyes. Just draw Among Us. So I tried.
Screenshot_107.jpg
DamageActor3_7.png added!
index.php

Making a "characters first appearance" drawing for my game. Now I just have to finish the sprite art animation for her grand entrance.​
ScreenShot_9_24_2022_7_56_24.png
New area being started today. It leads to one of the games 2 optional bosses.

Forum statistics

Threads
125,540
Messages
1,171,814
Members
164,611
Latest member
anonymouss
Top