Things I believe should change in the FileSystem

I’m just starting to play with the FileSystem module, so there may be more to come, but could you guys please make FileSystem.createDirectory() resolve true when its created or if its created, or make it reject if its already created. There’s no way of knowing, right now I have to do this:

FS.exists(FS.dataDirectory + '/user').then(function (userDirectoryExists) {
	if(!userDirectoryExists) {
		return FS.createDirectory(FS.dataDirectory + '/user').then(function (directoryCreated) {
			return true;
		}).catch(function (err) {
			return false;
		});
	} else {
		return true;
	}
}).then(function (directory) {
	if(userDirectoryExists) {
		
	}
});

I’m writing way too many if statements for something Promises solve automatically
If the change is made I could write this:

FS.createDirectory(FS.dataDirectory + '/user').then(function (userDirectoryExists) {
	console.log('Dir Exist:', userDirectoryExists); // true
});

If there’s a reason for that choice could someone please explain why perhaps I’m missing something

Same thing for writeTextToFile I’m just going as I code, I’m sure there’s more, most of these are not resolving anything just resolving.

Thanks for the suggestion :slight_smile:

While I don’t think the current API is broken, I agree with you that createDirectory returning a boolean could be useful. So we might consider changing this is the future.

However I don’t see why writeTextToFile should resolve to anything. Do you mean it return true if the current file already existed, and was overwritten? If that’s the case I don’t think I agree with that.

That would also add (a small) overhead, as it would require two IO operations instead of just one.