Androxilogin

Create a directory with blank files and subfolders of the same name.

Apr 26th, 2025 (edited)
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. @echo off
  2. setlocal enabledelayedexpansion
  3.  
  4. :: Get the full path to the current directory and the batch file itself
  5. set "baseDir=%cd%"
  6. set "outputDir=%baseDir%\Output"
  7. set "thisScript=%~f0"
  8.  
  9. :: Create Output directory if it doesn't exist
  10. if not exist "%outputDir%" (
  11. mkdir "%outputDir%"
  12. )
  13.  
  14. :: Call the recursive function to replicate the structure
  15. call :ReplicateStructure "%baseDir%" "%outputDir%"
  16. goto :eof
  17.  
  18. :ReplicateStructure
  19. set "sourceDir=%~1"
  20. set "targetDir=%~2"
  21.  
  22. :: Skip processing if we are in the Output folder or processing the batch file itself
  23. if /i "%sourceDir%"=="%outputDir%" (
  24. goto :eof
  25. )
  26.  
  27. :: Skip if the current source directory is the batch file itself
  28. if /i "%sourceDir%\%thisScript%"=="" (
  29. goto :eof
  30. )
  31.  
  32. :: Loop through the files in the current directory (excluding system files and folders)
  33. for /f "delims=" %%A in ('dir /b /a-d-h "%sourceDir%"') do (
  34. set "file=%%A"
  35. set "fullPath=%sourceDir%\!file!"
  36.  
  37. :: Skip the batch file itself
  38. if /i "!fullPath!"=="%thisScript%" (
  39. continue
  40. )
  41.  
  42. :: Create an empty file in the corresponding target directory
  43. type nul > "%targetDir%\!file!"
  44. )
  45.  
  46. :: Loop through directories and create them in the target directory
  47. for /f "delims=" %%D in ('dir /b /ad-h "%sourceDir%"') do (
  48. set "folder=%%D"
  49. set "fullPath=%sourceDir%\!folder!"
  50.  
  51. :: Skip the Output directory itself to avoid recursion
  52. if /i "!fullPath!"=="%outputDir%" (
  53. continue
  54. )
  55.  
  56. set "newTarget=%targetDir%\!folder!"
  57. mkdir "!newTarget!" >nul 2>&1
  58. call :ReplicateStructure "!fullPath!" "!newTarget!"
  59. )
  60.  
  61. goto :eof
  62.  
Advertisement
Add Comment
Please, Sign In to add comment