0

I have two batch files.

  1. First extracts date from and creates folder in \YEAR\MONTH\DATE format.

    @echo off setlocal enabledelayedexpansion :: Extract date fields for /f "tokens=1-4 delims=/-. " %%i in ('date /t') do ( set v1=%%i& set v2=%%j& set v3=%%k if "%%i:~0,1%%" gtr "9" (set v1=%%j& set v2=%%k& set v3=%%l) for /f "skip=1 tokens=2-4 delims=(-)" %%m in ('echo.^|date') do ( set %%m=!v1!& set %%n=!v2!& set %%o=!v3! ))</br> :: Final set for language independency set year=%yy%%aa% set month=%mm% set day=%dd% :: Make Dir set root=f:\ ::Create folder of today's date if exist %root% goto L2 goto L3 :L2 if not exist %root%\%year% md %root%\%year% :L3 if exist %root%\%year%\%month% goto L5 :L4 if not exist %root%\%year%\%month% md %root%\%year%\%month% :L5 md %root%\%year%\%month%\%day% :: Detete folder older than '3' days forfiles /p "%root%%year%\%month%" /s /d -3 /c "cmd /c IF @isdir == TRUE rd /S /Q @path" echo. pause

  2. creates a backup of database

    echo off cls echo -- BACKUP DATABASE -- ::set db name set DATABASENAME='db_name' :: set path and format set BACKUPFILENAME='path\%DATABASENAME%.bak' :: set server name set SERVERNAME='server name' echo. ::backup execution sqlcmd -S %SERVERNAME% -Q "BACKUP DATABASE [%DATABASENAME%] TO DISK = N'%BACKUPFILENAME%' WITH INIT , NOUNLOAD , NAME = N'%DATABASENAME% backup', NOSKIP , STATS = 10, NOFORMAT" echo.

Now I want to call the second batch file from first and also pass the parameters like root, year, month, date from first to second. I've tried both codes individually and its working perfectly. How can I pass the parameters. Please help

vrun
  • 3
  • 3

1 Answers1

0

If you call second batch from first one, something like

call backupDP.cmd

both files share the same environment, so, both see the same variables. No need to pass anything, the second batch already has all the data.

MC ND
  • 69,615
  • 8
  • 84
  • 126
  • Thanks @MC ND. But will the second file understand what root, year, month, date means – vrun Feb 24 '14 at 10:49
  • @vrun, i know i will not say anything new, but batch files are programs. Your question and my answer were about data interchange. It is the programmer task to code the program to make use of the data or understand what it means. Sorry, i don't have enough information to know how it will be used. – MC ND Feb 24 '14 at 12:39