Batch- Does Mkdir Skip over a Folder If It Already Exists and Move onto the Next One?

I am trying to create a Batch file that creates a series of folders in an already-existing directory. If part of the directory already exists, will MKDIR skip over that one and continue down the directory or will it overwrite it?

A sample code is here:

mkdir %cdriveletter%\Steam\SteamApps\common\Counter-Strike Source\cstrike\custom\my_custom_skins\

In that code I want to only create the MyCustomSkins folder but it has to be in that directory. I do not want it to overwrite the stuff before it.

Will this suffice?

1

1 Answer

The mkdir command will create any folders that do not exist in the specified path, unless extensions are disabled (setLocal enableExtensions) - regardless, it will not destroy a directory and create a new one with the same name.

See mkdir /? -

...

MKDIR creates any intermediate directories in the path, if needed.
For example, assume \a does not exist then:

    mkdir \a\b\c\d

is the same as:

    mkdir \a
    chdir \a
    mkdir b
    chdir b
    mkdir c
    chdir c
    mkdir d

which is what you would have to type if extensions were disabled.

You should probably also surround your path with quotation marks.

Note: You could test that yourself, by creating some 'test' directories, and writing a similar command.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest