Search code examples
batch-filecmdmkdirsteam

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?


Solution

  • 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.