Project Directory Structure – Script

I’ve often been thinking it could be useful to have a script that could create a directory structure for me based on a text file and a simple windows batch script.

Well here it is…

The default input file name is dirs.txt:

0 Project Name
1   Project Management
2     Plan
2     Issues
2     Resources
1   Deliverables
2     Configuration
3       Architecture
3       BR100s
3       MD50s
2     Development
3       MD70s
3       Source Code
2     Interfaces
3       Interface Strategy
2     Data Conversion
3       Data Conversion Strategy
2     Testing
3       Test Strategy
3       Test Script
;Comment again
1   Info
2     News
2     Contacts
2     Tools
2     This is a long dir name

The digit is the directory level – without this it is impossible to create a structure with a simple windows batch script.

The main script is makedirs.cmd:

@echo off
rem makedirs.cmd syntax:
rem %1 = target dir. default = current dir .
rem %2 = name of dir file. default = dirs.txt
  set targetdir=.
  if not "%1" == "" set targetdir=%1
  if not exist %targetdir% goto NODIR
  set dirfile=dirs.txt
  if not "%2" == "" set dirfile=%2
  if not exist %dirfile% goto NOFILE
  set sourcedir=%cd%
  echo Creating dirs in %targetdir%
  for /f "eol=; tokens=1* delims= " %%i in (%dirfile%) do call makedir %%i "%%j"
goto XIT
  echo Directory %targetdir% does not exist
goto XIT
  echo File %dirfile% does not exist
goto XIT
  echo Done…

This script does not need any parameters if the input file is "dirs.txt" and the target directory is current dir. See rem lines above for syntax.

The makedirs.cmd calls makedir.cmd which creates a single dir:

@echo off
rem makedir.cmd syntax:

rem %1 = level
rem %2 = dirname
set level=%1
set dirname=%~2
if "%level%"=="0" goto LEVEL0
if not "%dirpath0%"=="" goto LEVELX
  rem special case where no 0 level line defined
  set dirpath0=%targetdir%
  rem done – now continue as normal
  set /a above=%level%-1
  set dirpath=!dirpath%above%!
  set dirpath%level%=%dirpath%\%dirname%
  rem echo mkdir "!dirpath%level%!"
  mkdir "!dirpath%level%!"
goto XIT
  rem no level 0 line defined so use current dir as top
  set dirpath0=.
goto XIT
  rem level 0 line defined so set top as current plus dirname
  set dirpath0=%targetdir%\%dirname%
  rem echo mkdir "%dirpath0%"
  mkdir "%dirpath0%"
goto XIT

This script is not meant to be used on its own.

This entry was written by Kent Willumsen , posted on Sunday August 15 2010at 12:08 pm , filed under Project Management, Project Technology and tagged , . Bookmark the permalink . Post a comment below or leave a trackback: Trackback URL.

Comments are closed.