Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- setlocal enabledelayedexpansion
- :: Get the full path to the current directory and the batch file itself
- set "baseDir=%cd%"
- set "outputDir=%baseDir%\Output"
- set "thisScript=%~f0"
- :: Create Output directory if it doesn't exist
- if not exist "%outputDir%" (
- mkdir "%outputDir%"
- )
- :: Call the recursive function to replicate the structure
- call :ReplicateStructure "%baseDir%" "%outputDir%"
- goto :eof
- :ReplicateStructure
- set "sourceDir=%~1"
- set "targetDir=%~2"
- :: Skip processing if we are in the Output folder or processing the batch file itself
- if /i "%sourceDir%"=="%outputDir%" (
- goto :eof
- )
- :: Skip if the current source directory is the batch file itself
- if /i "%sourceDir%\%thisScript%"=="" (
- goto :eof
- )
- :: Loop through the files in the current directory (excluding system files and folders)
- for /f "delims=" %%A in ('dir /b /a-d-h "%sourceDir%"') do (
- set "file=%%A"
- set "fullPath=%sourceDir%\!file!"
- :: Skip the batch file itself
- if /i "!fullPath!"=="%thisScript%" (
- continue
- )
- :: Create an empty file in the corresponding target directory
- type nul > "%targetDir%\!file!"
- )
- :: Loop through directories and create them in the target directory
- for /f "delims=" %%D in ('dir /b /ad-h "%sourceDir%"') do (
- set "folder=%%D"
- set "fullPath=%sourceDir%\!folder!"
- :: Skip the Output directory itself to avoid recursion
- if /i "!fullPath!"=="%outputDir%" (
- continue
- )
- set "newTarget=%targetDir%\!folder!"
- mkdir "!newTarget!" >nul 2>&1
- call :ReplicateStructure "!fullPath!" "!newTarget!"
- )
- goto :eof
Advertisement
Add Comment
Please, Sign In to add comment