consolefs v2.0.6
ConsoleFS-JavaScript-Module
ConsoleFS is a open-source alternative to FS with easier use made by Javier107 (Current version : 2.0.6)
To-do list :
- Add rename function
- Add move function
- Add copy function
- Add function for read a directory
- Add functions for append to JSON, ENV and INI files
Extra :
- ConsoleFS only works on Windows, Linux and Mac
- ConsoleFS supports relative paths
Changelog :
- 2.0.6
- Fix list.js's error (Another one)
- 2.0.5
- Fixed list.js and other details
- 2.0.4
- Fixed 2.0.3's big error with the list function
- 2.0.3 (Hidden)
- Added function for read a directory
- 2.0.2
- Created a changelog in README.md
- Fixed error with \\n in linux/mac
- Fixed error with the append function that overwrited instead
Installing
# Installing ConsoleFS
npm i consoleFS
Usage
Basics
Setup and basic functions like checking, deleting and other small things can be found on this sub-section
- Requiring ConsoleFS
// Requiring ConsoleFS
const ConsoleFS = require('consolefs');
- Checking a file or directory's existence
- You must pass as argument a string that contains the full/relative path of the file/dir you want to check
- ConsoleFS.exist() returns a boolean value
// Checking if a file or directory exists
if (ConsoleFS.exist(file)) {
// File/Dir exists
} else {
// File/Dir don't exists
};
- Deleting a file or directory
- You must pass as argument a string that contains the full/relative path of the file/dir you want to delete
- ConsoleFS.del() don't asks before deleting. It just deletes. so be careful where you use this. I don't make responsable if you delete a important file on your PC because you must be aware of what you do when managing files using ConsoleFS
// Deleting a file or directory
ConsoleFS.del(file);
- Detect if a path is a file or directory
- You must pass as argument a string that contains the full/relative path of the path you want to check
- ConsoleFS.typeof() returns a string which can be 'file' or 'directory'
- ConsoleFS.typeof() can't get the type of a path if it doens't exist
// Checking the type of a file/directory
var type = ConsoleFS.typeof(path);
// type can be 'file' or 'directory'
- Get the files and folders in a directory
- You must pass as argument a string that contains the full/relative path of the path you want to check
- Optionally, you can pass an object with the properties "files" and "folders" which must be booleans.
- When an object is used, it will return only the files or folders depending what is enabled and what disabled
- If no object is used, then folders and files will be returned
- ConsoleFS.list() returns an array with the contents of the directory
- ConsoleFS.list() can't read a directory if it doens't exist
// Reading the contents of a directory
var files = ConsoleFS.list(path, {
files: true,
folders: false
});
Writing
ConsoleFS.write can't create a file if the directory where is created doens't exists. ConsoleFS.write overwrites files in case they exist so be careful. I don't make responsable if you overwrite a important file on your PC because you must be aware of what you do when managing files using ConsoleFS
- Writing a text file
- You must pass as argument a string which contains the text you want to include on the file
- You must pass as argument a string that contains the full/relative path of the file you're gonna write
// Writing a text file
ConsoleFS.write.INT(text, file);
- Writing a JSON file
- You must pass as argument a object so is converted to JSON
- You must pass as argument a string that contains the full/relative path of the file you're gonna write
// Writing a JSON file
ConsoleFS.write.JSON(object, file);
- Writing a INI file
- You must pass as argument a object that follows the same structure of the object returned when reading a INI file
- You must pass as argument a string that contains the full/relative path of the file you're gonna write
// Writing a INI file
ConsoleFS.write.INI(object, file);
- Writing a file with HEX values
- You must pass as argument a buffer with the values you're gonna use for write the file
- You must pass as argument a string that contains the full/relative path of the file you're gonna write
// Writing a file with HEX values
ConsoleFS.write.HEX(buffer, file);
- Writing a ENV file
- You must pass as argument a object with only strings inside
- You must pass as argument a string that contains the full/relative path of the file you're gonna write
// Writing a ENV file
ConsoleFS.write.ENV(object, file);
Appending
ConsoleFS.append can't add to a file that doens't exists. ConsoleFS.append.INT and ConsoleFS.append.HEX adds values/characters after the last value/character on the file.
- Adding text to a file
- You must pass as argument a string which contains the text you want to add to the file
- You must pass as argument a string that contains the full/relative path of the file where you'll add the text
// Adding text to a file
ConsoleFS.append.INT(text, file);
- Adding HEX values to a file
- You must pass as argument a buffer with the values you want to add to the file
- You must pass as argument a string that contains the full/relative path of the file where you'll add the text
// Adding HEX values to a file
ConsoleFS.append.HEX(buffer, file);
- Adding an object to a INI file
- You must pass as argument a object that follows the same structure of the object returned when reading a INI file
- You must pass as argument a string that contains the full/relative path of the file where you'll add the text
- The object and the file will be combined and the keys that already exist on the file will be replaced with the new ones
// Adding an object to a INI file
ConsoleFS.append.INI(object, file);
- Adding an object to a JSON file
- You must pass as argument a object so is converted to JSON
- You must pass as argument a string that contains the full/relative path of the file where you'll add the text
- The object and the file will be combined. The objects will be merged and other values will be replaced by the new ones if they exist
// Adding an object to a JSON file
ConsoleFS.append.JSON(object, file);
- Adding an object to a ENV file
- You must pass as argument a object that only has strings inside
- You must pass as argument a string that contains the full/relative path of the file where you'll add the text
- The object and the file will be combined and the keys that already exist on the file will be replaced with the new ones
// Adding an object to a ENV file
ConsoleFS.append.ENV(object, file);
Reading
ConsoleFS.read doens't generates cache so the result is always updated.
- Reading a text file
- You must pass as argument a string that contains the full/relative path of the file you want to read
- The content of the file is returned as a string
// Reading a text file
var contentTXT = ConsoleFS.read.INT(file);
- Reading a JSON file
- You must pass as argument a string that contains the full/relative path of the file you want to read
- The content of the file is returned as a object
// Reading a JSON file
var contentJSON = ConsoleFS.read.JSON(file);
- Reading a INI file
- You must pass as argument a string that contains the full/relative path of the file you want to read
- The content of the file is returned as a object
- The format of the returned object is
Object[Section][Key]
// Reading a INI file
var contentINI = ConsoleFS.read.INI(file);
- Reading a ENV file
- You must pass as argument a string that contains the full/relative path of the file you want to read
- The keys on the file are added to
process.env
with their respective values. - The function returns an array which contains the keys that the file had which were added to
process.env
// Reading a ENV file
var keysENV = ConsoleFS.read.ENV(file);
- Reading the HEX values of a file
- You must pass as argument a string that contains the full/relative path of the file you want to read
- The HEX values of the file is returned as a buffer
// Reading a file's HEX values
var contentHEX = ConsoleFS.read.HEX(file);
Other
- Github Repo
- Glitch Repo
- NPM
- Discord : Javier107#6900