How to open file just if exists


Is there a way to open a file just if it exists?

I allready tried both ‘AtomEnvironment::open’ and ‘atom.workspace::open’ but didn’t find a way to previously check if a file exists. Has anyone encountered a simillar issue and is able to help?


I’m new to developing for Atom, but in node.js you would use either fs.statSync or fs.accessSync for checking if a file exists, before performing operations on it…


Thanks a lot for the reply! fs.statSync was really helpfull indeed. My solution:

const fs = require(‘fs’);
try {
} catch(e) {

Maybe not the most elegant way, but it’s working :slight_smile: