Creating a directory under the same series of subdirectories

Discussion in 'Windows 10' started by DeathStalker77, Oct 19, 2020.

  1. DeathStalker77

    DeathStalker77 MDL Addicted

    Nov 8, 2009
    552
    40
    30
    Hello all!

    currently I have a folder structure such as:

    C:\folder 1\folder 2\
    C:\folder 1\folder 2\folder 3

    and I want to create a subfolder within each of them -

    C:\folder 1\folder 2\last folder
    C:\folder 1\folder 2\folder 3\last folder

    Such that if last folder already exists, it skips it (error or not).

    Does anyone know if/how this could be done? I've tried makdir several ways with no success :( and have found no programs that can do it.

    Any ideas?
     
  2. GezoeSloog

    GezoeSloog knows a guy, who knows another guy.

    Feb 10, 2012
    864
    8,150
    30
    Code:
    for /f "usebackq delims=" %%P in (`dir "C:\folder 1" /a:d /b /s`) do md "%%P\last folder"
     
  3. nechrist

    nechrist MDL Guide Pack

    Apr 24, 2010
    326
    163
    10
    @DeathStalker77 the @GezoeSloog code works greate and create the given folder in each of the subfolders. If you want to make a check if the given folder already exist you can have something like this:

    Code:
    @echo off
    cls
    echo.
    set /p rootfold=Insert root folder full path (ex c:\temp):
    echo.
    set /p newfold=Insert the name of the folder you want to create:
    echo.
    dir "%rootfold%" /a:d /b /s | findstr /i "%newfold%" >nul
    if %errorlevel% EQU 0 goto done
    for /f "usebackq delims=" %%P in (`dir "%rootfold%" /a:d /b /s`) do (
    md "%%P\%newfold%"
    )
    echo The folder %newfold% created successfully...
    echo.
    pause
    goto :EOF
    
    :DONE
    echo The folder %newfold% already exist. Skipping...
    echo.
    pause
    goto :EOF
    
    Customize the code as you like / needs.
     
  4. Thanks