bitburner-src/doc/source/netscript/basicfunctions/fileExists.rst

30 lines
1.2 KiB
ReStructuredText
Raw Normal View History

fileExists() Netscript Function
===============================
2021-03-12 08:51:56 +01:00
.. js:function:: fileExists(filename[, hostname])
:RAM cost: 0.1 GB
2021-03-12 08:51:56 +01:00
:param string filename: Filename of file to check.
:param string hostname:
Hostname of target server. This is optional. If it is not specified then
the function will use the current server as the target server.
:returns: ``true`` if the file exists, ``false`` if it doesn't.
2021-03-12 08:51:56 +01:00
The filename for scripts is case-sensitive, but for other types of files it
is not. For example, ``fileExists("brutessh.exe")`` will work fine, even
though the actual program is named ``BruteSSH.exe``.
2021-03-12 08:51:56 +01:00
If the ``hostname`` argument is omitted, then the function will search
through the server running the script that calls this function for the file.
2021-03-12 08:51:56 +01:00
Examples:
2021-03-12 08:51:56 +01:00
.. code-block:: javascript
2023-01-06 13:43:09 +01:00
ns.fileExists("foo.js", "foodnstuff"); // returns: false
ns.fileExists("ftpcrack.exe"); // returns: true
2021-03-12 08:51:56 +01:00
2023-01-06 13:43:09 +01:00
The first example above will return true if the script named ``foo.js`` exists on the ``foodnstuff`` server, and false otherwise.
2021-03-12 08:51:56 +01:00
The second example above will return true if the current server contains the ``FTPCrack.exe`` program, and false otherwise.