How to use the fs-extra.stat function in fs-extra

To help you get started, we’ve selected a few fs-extra examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Unity-Technologies / unity-cache-server / stream_player.js View on Github external
});

        await new Promise(resolve => {
            nullServer.listen(0, "0.0.0.0", () => resolve());
        });
    }

    if(nullServer !== null) {
        options.nullServer = true;
        const a = nullServer.address();
        serverAddress = `${a.address}:${a.port}`;
    }

    // Gather files
    const files = [];
    const stat = await fs.stat(filePath);
    if(stat.isDirectory()) {
        await helpers.readDir(filePath, f => files.push(f.path));
    }
    else {
        files.push(filePath);
    }

    // Validate files
    const verBuf = Buffer.alloc(consts.VERSION_SIZE, 'ascii');
    for(let i = 0; i < files.length; i++) {
        const fd = await fs.open(files[i], "r");
        await fs.read(fd, verBuf, 0, consts.VERSION_SIZE, 0);
        if(helpers.readUInt32(verBuf) !== consts.PROTOCOL_VERSION) {
            if(options.verbose) {
                console.log(`Skipping unrecognized file ${files[i]}`);
            }
github otris / vscode-janus-debug / src / helpers.ts View on Github external
return new Promise((resolve, reject) => {
        // todo remove
        const allowCreateFolder = false;
        fs.stat(scriptPath, function(err1: any, stats1: any) {
            if (err1) {
                if (allowCreateFolder && 'ENOENT' === err1.code && 'js' !== path.extname(scriptPath)) {
                    const p = scriptPath.split(path.sep);
                    const newfolder = p.pop();
                    const _path = p.join(path.sep);
                    fs.stat(_path, (err2: any, stats2: any) => {
                        if (err2) {
                            if ('ENOENT' === err2.code) {
                                reject('can only create a single subfolder on a valid path');
                            } else {
                                reject(err2.message);
                            }
                        } else {
                            if (stats2.isDirectory()) {
                                if (newfolder) {
                                    resolve(path.join(_path, newfolder));
github egodigital / ego-cli / src / commands / backup / index.ts View on Github external
}

        // copy files
        {
            const FILES = SRC_ENTRIES.filter(e => e.stat.isFile());

            for (const F of FILES) {
                let copyFile = true;
                let operationStart = 'Copy';
                let operationFinished = 'copied';

                const DEST_PATH = path.resolve(
                    path.join(dest, F.name)
                );
                if (await exists(DEST_PATH)) {
                    const DEST_STAT = await fs.stat(DEST_PATH);
                    if (DEST_STAT.isFile()) {
                        copyFile = !this._areFilesEqual(F.stat, DEST_STAT);

                        operationStart = 'Update';
                        operationFinished = 'updated';
                    }
                }

                if (copyFile) {
                    const REL_SRC_PATH = path.relative(rootDir, F.path);

                    await withSpinnerAsync(`🚛 ${operationStart} ${colorize(REL_SRC_PATH)} ...`, async (spinner) => {
                        await fs.copy(
                            F.path, DEST_PATH,
                            {
                                overwrite: true,
github microsoft / vscode-cosmosdb / src / mongo / tree / MongoDatabaseTreeItem.ts View on Github external
return fsPath;
						} else {
							throw new UserCancelledError();
						}
					}
				} else if (response === browse) {
					vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://docs.mongodb.com/manual/installation/'));
					// default down to cancel error because MongoShell.create errors out if undefined is passed as the shellPath
				}

				throw new UserCancelledError();
			}
		} else {
			// User has specified the path or command.  Sometimes they set the folder instead of a path to the file, let's check that and auto fix
			if (await fse.pathExists(shellPathSetting)) {
				let stat = await fse.stat(shellPathSetting);
				if (stat.isDirectory()) {
					return path.join(shellPathSetting, mongoExecutableFileName);
				}
			}

			return shellPathSetting;
		}
	}
}
github atom / github / lib / git-shell-out-strategy.js View on Github external
async resolveDotGitDir() {
    try {
      await fs.stat(this.workingDir); // fails if folder doesn't exist
      const output = await this.exec(['rev-parse', '--resolve-git-dir', path.join(this.workingDir, '.git')]);
      const dotGitDir = output.trim();
      return toNativePathSep(dotGitDir);
    } catch (e) {
      return null;
    }
  }
github bigstepinc / jsonrpc-bidirectional / src / NodeMultiCoreCPUBase / MasterEndpoint.js View on Github external
async() => {
				try
				{
					if(nPackageJSONModificationTime !== (await fs.stat(strPackageJSONPath)).mtime.getTime())
					{
						nPackageJSONModificationTime = (await fs.stat(strPackageJSONPath)).mtime.getTime();
						strVersionNew = JSON.parse(await fs.readFile(strPackageJSONPath, "utf8")).version;
					}

					if(strVersionNew !== strVersion)
					{
						clearInterval(nIntervalID);

						console.log(`
							Updated. 
							Detected new version ${strVersionNew}. 
							Old version ${strVersion}. 
							Attempting to exit gracefully to allow starting with new version.
						`.replace(/^\t+/gm, ""));

						await this.gracefulExit(null);
					}
github kevindavus / personal-goals-cli / src / commands / new.js View on Github external
async function newGoal(type, goal): Promise {
  checkConf();
  const date = moment().format("MMMDDYYYYHHmm");
  const file = getFileName(type, goal);
  const filePath = getFileName(type);
  const completedFile = getFileName(path.join("completed", type, date), goal);
  fs.stat(completedFile, async function(err, stat) {
    if (err == null) {
      //file exists
      console.log("Moving goal from completed to " + type);
      fs.rename(file, completedFile);
    } else if (err.code == "ENOENT") {
      fs.stat(file, async function(err2, stat2) {
        if (err2 == null) {
          //file exists
          console.log("Goal already exists");
        } else if (err2.code == "ENOENT") {
          fs.ensureDirSync(filePath);
          //file does not exist
          fs.close(fs.openSync(file, "w"));
        }
      });
    }
github N0taN3rd / chrome-remote-interface-extra / scripts / generateIndex.js View on Github external
async function isPathToFile (filePath) {
  const stat = await fs.stat(filePath)
  return stat.isFile()
}
github bigstepinc / jsonrpc-bidirectional / src / NodeMultiCoreCPUBase / MasterEndpoint.js View on Github external
async watchForUpgrade(strPackageJSONPath)
	{
		assert(typeof strPackageJSONPath === "string");

		if(this._bWatchingForUpgrade)
		{
			return;
		}

		this._bWatchingForUpgrade = true;

		const strVersion = JSON.parse(await fs.readFile(strPackageJSONPath, "utf8")).version;
		let nPackageJSONModificationTime = (await fs.stat(strPackageJSONPath)).mtime.getTime();
		let strVersionNew = strVersion;

		const nIntervalMilliseconds = 10 * 1000;

		const nIntervalID = setInterval(
			async() => {
				try
				{
					if(nPackageJSONModificationTime !== (await fs.stat(strPackageJSONPath)).mtime.getTime())
					{
						nPackageJSONModificationTime = (await fs.stat(strPackageJSONPath)).mtime.getTime();
						strVersionNew = JSON.parse(await fs.readFile(strPackageJSONPath, "utf8")).version;
					}

					if(strVersionNew !== strVersion)
					{
github roblox-ts / roblox-ts / src / Project.ts View on Github external
public async cleanDirRecursive(dir: string) {
		if (await fs.pathExists(dir)) {
			for (const name of await fs.readdir(dir)) {
				const filePath = path.join(dir, name);
				if ((await fs.stat(filePath)).isDirectory()) {
					await this.cleanDirRecursive(filePath);
					if ((await fs.readdir(filePath)).length === 0) {
						await fs.rmdir(filePath);
					}
				} else {
					let ext = path.extname(filePath);
					let baseName = path.basename(filePath, ext);
					let subext = path.extname(baseName);
					baseName = path.basename(baseName, subext);
					const relativeToOut = path.dirname(path.relative(this.outPath, filePath));
					const rootPath = path.join(this.rootPath, relativeToOut);
					if (ext === ".lua") {
						let exists = false;
						exists = exists || (await fs.pathExists(path.join(rootPath, baseName) + subext + ".ts"));
						exists = exists || (await fs.pathExists(path.join(rootPath, baseName) + subext + ".tsx"));
						exists =