prevent app from creating windows system folders using regex?

I’m building a browser-based app which allows users to create folders with some .json files (not big deal). The thing is, the framework that I’m using (NW.js) doesn’t appears to care about allowing users to create folders named "CON" or "NUL"; These are not supposed to be created, the files inside just vanish and it’s somewhat difficult to delete the folder themselves.

I can no problem make something like this to prevent to happen:

var newFolder = "nul";
function checkFolderName(text) {
    switch(newFolder) {
    case "con":
        console.log("folder can't be created")

    case "nul":
        console.log("folder can't be created")

    // and so on... there's about 23 windows-reserved names that I could find

        console.log("folder can be created")

But I wonder if there is some easier way to check this through Regex/Javascript, or maybe some different approach to this idea.

Source: JavaSript – Stack Overflow

November 29, 2021
Category : News
Tags: directory | javascript | nwjs | regex | Windows

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.