Squash -
Here is my script. The purpose of this script is to to establish a POV folder structure for automation at net new client engagements. This 'POV' has been agreed on by multiple colleagues.
Depending on what folder structure option is established, the environment file (_env.cmd) needs to be dynamic to capture the MAINPATH variable value.
So I was hoping to redirect those strings to the _env.cmd on the fly.
Code: Select all
ECHO \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
ECHO \\ \\
ECHO \\ Establish \\
ECHO \\ POV Folder Structure \\
ECHO \\ \\
ECHO \\ EPM Practice \\
ECHO \\ \\
ECHO \\ 0 0 0 0 0 \\
ECHO \\ \/!\/ (=!!=) \/!\/\/!\/ \\
ECHO \\ / \ /\ /\ / \ / \ \\
ECHO \\ \\
ECHO \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
TIMEOUT /T 3 >NUL
CLS
ECHO ***************************************************************
ECHO Please specificy the drive where automation will be established
ECHO ***************************************************************
ECHO.
ECHO [1] C
ECHO [2] D
ECHO [3] E
ECHO [4] F
ECHO [5] G
ECHO [6] H
ECHO [7] I
ECHO [8] J
ECHO.
CHOICE /N /C 12345678 /M "Option: "
IF ERRORLEVEL 8 SET DRIVEL=J
IF ERRORLEVEL 7 SET DRIVEL=I
IF ERRORLEVEL 6 SET DRIVEL=H
IF ERRORLEVEL 5 SET DRIVEL=G
IF ERRORLEVEL 4 SET DRIVEL=F
IF ERRORLEVEL 3 SET DRIVEL=E
IF ERRORLEVEL 2 SET DRIVEL=D
IF ERRORLEVEL 1 SET DRIVEL=C
SET DRIVE=%DRIVEL%:\
SET MAINPATH=%DRIVE%Hyperion_Batch\
CLS
ECHO ***********************************************************
ECHO Will there be more than 1 application requiring automation?
ECHO ***********************************************************
ECHO.
ECHO [1] Yes
ECHO [2] No
ECHO.
CHOICE /N /C 12 /M "Option: "
IF ERRORLEVEL 2 GOTO 1
CLS
ECHO *****************************************
ECHO How many applications require automation?
ECHO *****************************************
ECHO.
CHOICE /N /C 12345678 /M "Option: "
IF ERRORLEVEL 8 SET APP_NUM=APP_1,APP_2,APP_3,APP_4,APP_5,APP_6,APP_7,APP_8 & SET AN=8
IF ERRORLEVEL 7 SET APP_NUM=APP_1,APP_2,APP_3,APP_4,APP_5,APP_6,APP_7 & SET AN=7
IF ERRORLEVEL 6 SET APP_NUM=APP_1,APP_2,APP_3,APP_4,APP_5,APP_6 & SET AN=6
IF ERRORLEVEL 5 SET APP_NUM=APP_1,APP_2,APP_3,APP_4,APP_5 & SET AN=5
IF ERRORLEVEL 4 SET APP_NUM=APP_1,APP_2,APP_3,APP_4 & SET AN=4
IF ERRORLEVEL 3 SET APP_NUM=APP_1,APP_2,APP_3 & SET AN=3
IF ERRORLEVEL 2 SET APP_NUM=APP_1,APP_2 & SET AN=2
IF ERRORLEVEL 1 SET APP_NUM=APP_1 & SET AN=1
CLS
ECHO ************************************************************************
ECHO Best practice is to dedicate an automation directory to each application
ECHO.
ECHO This segregates processes keeping directories clean and easily navigable
ECHO ------------------------------------------------------------------------
ECHO.
ECHO For instance, if you had 3 applications, the directories would like such^:
ECHO.
ECHO C:\Automation_Batch\APP_1\Hyperion_Batch\etc...
ECHO C:\Automation_Batch\APP_2\Hyperion_Batch\etc...
ECHO C:\Automation_Batch\APP_2\Hyperion_Batch\etc...
ECHO.
ECHO Otherwise, all automation would reside in a single directory like such^:
ECHO.
ECHO C:\Hyperion_Batch\etc...
ECHO.
ECHO ************************************************************************
ECHO.
ECHO [1] Establish a single automation directory
ECHO.
ECHO [2] Establish application specific directories
ECHO.
CHOICE /N /C 12 /M "Option: "
ECHO.
IF ERRORLEVEL 2 GOTO 2
CLS
:1
ECHO ************************************************
ECHO Establishing the POV Folder Structure...
ECHO ************************************************
SET "FLG=1"
IF NOT EXIST %MAINPATH%Archives MKDIR %MAINPATH%Archives
IF NOT EXIST %MAINPATH%Data MKDIR %MAINPATH%Data
IF NOT EXIST %MAINPATH%Errors MKDIR %MAINPATH%Errors
IF NOT EXIST %MAINPATH%Files\Imports MKDIR %MAINPATH%Files\Imports
IF NOT EXIST %MAINPATH%Files\Exports MKDIR %MAINPATH%Files\Exports
IF NOT EXIST %MAINPATH%Files\Backups MKDIR %MAINPATH%Files\Backups
IF NOT EXIST %MAINPATH%Locks MKDIR %MAINPATH%Locks
IF NOT EXIST %MAINPATH%Logs MKDIR %MAINPATH%Logs
IF NOT EXIST %MAINPATH%Scripts\MaxL MKDIR %MAINPATH%Scripts\MaxL
IF NOT EXIST %MAINPATH%Scripts\Utilities\PsTools MKDIR %MAINPATH%Scripts\Utilities\PsTools
IF NOT EXIST %MAINPATH%Scripts\SQL MKDIR %MAINPATH%Scripts\SQL
IF NOT EXIST %MAINPATH%Scripts\Batch MKDIR %MAINPATH%Scripts\Batch
GOTO FNDRPLC
:2
ECHO ************************************************
ECHO Establishing the POV Folder Structure...
ECHO ************************************************
SET MAINPATH=
SET MAINPATH=%DRIVE%Automation_Batch\
SET "FLG=2"
FOR /D %%f IN (%APP_NUM%) do (
IF NOT EXIST %MAINPATH%%%f\Hyperion_Batch\Archives MKDIR %MAINPATH%%%f\Hyperion_Batch\Archives
IF NOT EXIST %MAINPATH%%%f\Hyperion_Batch\Data MKDIR %MAINPATH%%%f\Hyperion_Batch\Data
IF NOT EXIST %MAINPATH%%%f\Hyperion_Batch\Errors MKDIR %MAINPATH%%%f\Hyperion_Batch\Errors
IF NOT EXIST %MAINPATH%%%f\Hyperion_Batch\Files\Imports MKDIR %MAINPATH%%%f\Hyperion_Batch\Files\Imports
IF NOT EXIST %MAINPATH%%%f\Hyperion_Batch\Files\Exports MKDIR %MAINPATH%%%f\Hyperion_Batch\Files\Exports
IF NOT EXIST %MAINPATH%%%f\Hyperion_Batch\Files\Backups MKDIR %MAINPATH%%%f\Hyperion_Batch\Files\Backups
IF NOT EXIST %MAINPATH%%%f\Hyperion_Batch\Locks MKDIR %MAINPATH%%%f\Hyperion_Batch\Locks
IF NOT EXIST %MAINPATH%%%f\Hyperion_Batch\Logs MKDIR %MAINPATH%%%f\Hyperion_Batch\Logs
IF NOT EXIST %MAINPATH%%%f\Hyperion_Batch\Scripts\MaxL MKDIR %MAINPATH%%%f\Hyperion_Batch\Scripts\MaxL
IF NOT EXIST %MAINPATH%%%f\Hyperion_Batch\Scripts\Utilities\PsTools MKDIR %MAINPATH%%%f\Hyperion_Batch\Scripts\Utilities\PsTools
IF NOT EXIST %MAINPATH%%%f\Hyperion_Batch\Scripts\SQL MKDIR %MAINPATH%%%f\Hyperion_Batch\Scripts\SQL
IF NOT EXIST %MAINPATH%%%f\Hyperion_Batch\Scripts\Batch MKDIR %MAINPATH%%%f\Hyperion_Batch\Scripts\Batch
)
CLS
color CF
ECHO ***************************************************************************
ECHO %AN% application specific automation directories have been established
ECHO.
ECHO The directories are as follows:
echo.
FOR /D %%f IN (%APP_NUM%) do ( echo %MAINPATH%%%f )
ECHO.
ECHO Change APP_1-%AN% names accordingly
ECHO ***************************************************************************
PAUSE
color 0f
CLS
:FNDRPLC
setLocal enableDelayedExpansion
set filename="%CD%\_env_Setup.cmd"
set OT1=ABC
set OT2=DEF
set OT3=GHI
IF %FLG%==1 SET RT1=
IF %FLG%==1 SET RT2=SET MAINPATH=%DRIVE%Hyperion_Batch\
IF %FLG%==1 SET RT3=SET MAINFOLDER=%DRIVE%Hyperion_Batch\
IF %FLG%==2 SET RT1=for %%a in (%~f0\..\..\..\..\.) do SET APP=%%~nxa
IF %FLG%==2 SET RT2=SET MAINPATH=%DRIVE%Automation_Batch\%APP%\Hyperion_Batch\
IF %FLG%==2 SET RT3=SET MAINFOLDER=%DRIVE%Automation_Batch\%APP%\Hyperion_Batch\
for /f "tokens=*" %%a in ('type %filename%') do (
set "line=%%a"
if defined line (
call set "line=%%line:%OT1%=%RT1%%%"
call set "line=%%line:%OT2%=%RT2%%%"
call set "line=%%line:%OT3%=%RT3%%%"
echo !line!>>"%CD%\_env.cmd"
) else (
echo.
)
)
PAUSE
IF %FLG%==2 GOTO C2
SET MAINPATH=%DRIVE%Hyperion_Batch\
ECHO F | XCOPY /F /Y _env.cmd %MAINPATH%Scripts\Batch\_env.cmd
ECHO F | XCOPY /F /Y SAMPLE.cmd %MAINPATH%Scripts\Batch\SAMPLE.cmd
DEL "%CD%\_env_Setup.cmd"
DEL "%CD%\_env.cmd"
DEL "%CD%\SAMPLE.cmd"
PAUSE
GOTO WARN
:C2
FOR /D %%f IN (%APP_NUM%) do (
SET MAINPATH=%DRIVE%Automation_Batch\
ECHO F | XCOPY /F /Y _env.cmd %MAINPATH%%%f\Hyperion_Batch\Scripts\Batch\_env.cmd
ECHO F | XCOPY /F /Y SAMPLE.cmd %MAINPATH%%%f\Hyperion_Batch\Scripts\Batch\SAMPLE.cmd
DEL "%CD%\_env_Setup.cmd"
DEL "%CD%\_env.cmd"
DEL "%CD%\SAMPLE.cmd"
)
PAUSE
:WARN
SET W=WARN.txt
IF EXIST "%W%" DEL "%W%"
ECHO *********************************************************************>>%W%
ECHO The POV folder structure has been established successfully! >>%W%
ECHO *********************************************************************>>%W%
ECHO.
ECHO As of Spring 2016, blah blah blah
ECHO Adding content here
ECHO Still in progress
ECHO.
ECHO Thank you,
ECHO EPM Practice
ECHO.
ECHO ********************************************************************* >>%W%
ECHO ***************** All Scripts Self-Destructing... ******************* >>%W%
ECHO ********************************************************************* >>%W%
TIMEOUT /T 2>NUL
IF EXIST "%W%" start "" notepad.exe "%W%"
CLS
ECHO ******************************************************************
ECHO The Peloton POV folder structure has been established successfully
ECHO ******************************************************************
TIMEOUT /T 2 >NUL
CLS
ECHO \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
ECHO \\ \\
ECHO \\ POV \\
ECHO \\ Folder Structure Established \\
ECHO \\ \\
ECHO \\ EPM Practice \\
ECHO \\ \\
ECHO \\ 0 0 \\
ECHO \\ \/!\/ \/!\/ \\
ECHO \\ / \ / \ \\
ECHO \\ \\
ECHO \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
TIMEOUT /T 4 >NUL
DEL "%W%"
start /b "" cmd /c del "%~f0"&exit /b
The file that is read into the find and replace section, looks like this for the (3) lines I want to find & replace:
@ECHO OFF
REM ******************************************************************************************
REM
REM Name: env.cmd (Environment File)
REM
REM Description: This environment file is set to hold all variables for all Hyperion
REM scripts requiring user id, pwd, server, db, app, and path variables.
REM
REM Author:
REM Date:
REM
REM ******************************************************************************************
REM --------------------------------
REM SET PATH VARIABLES
REM --------------------------------
ABC
DEF
GHI
SET ARCHIVEPATH=Archives\
SET DATAPATH=Data\
SET ERRORPATH=Errors\
SET FILEPATH=Files\
SET EXPORTPATH=Exports\
SET IMPORTPATH=Imports\
SET BACKUPPATH=Backups\
SET LOCKPATH=Locks\
SET LOGPATH=Logs\
SET SCRIPTPATH=Scripts\NTScripts\
SET MAXLSCRIPTPATH=Scripts\MaxL\
SET UTILPATH=Scripts\Utilities\
SET SQLPATH=Scripts\SQL\
So, depending on which folder structure is set up, it replaces the above strings with the appropriate syntax to be able to capture the drive letter and directory's down to
Hyperion_Batch as that is the value for the MAINPATH variable.