DayLaborer
Programmer
I am trying to write a script that will show the name of all files in directory
and their age. I got this to work by creating a single CMD file. However, when I split
the code into two CMD files so that some of it can be reused elsewhere, I am having
difficulty passing variables back from the child CMD file to the parent CMD file. Please help.
Thanks!
Eliezer
and their age. I got this to work by creating a single CMD file. However, when I split
the code into two CMD files so that some of it can be reused elsewhere, I am having
difficulty passing variables back from the child CMD file to the parent CMD file. Please help.
Code:
REM *************************************************************************************
REM abc.cmd
REM this script is supposed to display the name of each file in a directory
REM and its age.
for /f "tokens=1,4" %%a in ('dir D:\MSG\*.TXT ^| find "/"') do (
call age.cmd %%a
echo %%b: %difference%
)
REM *************************************************************************************
REM *************************************************************************************
REM age.cmd
REM this script takes a date in mm/dd/yyyy format as an input parameter. It finds
REM the number of days between this date and the current system date by running
REM an SQL Server query. It connects to the SQL server database using
REM Windows authentication.
REM NOTE: I have tested this code separately and it works fine. The problem is
REM that I cannot pass a variable back to the CMD file that calls this CMD file.
for /f %%t in ('isql -S ^(local^) -E -Q "select datediff(d,getdate(),'%1')" ^| find "-" ^| findstr /R /C:"[0-9]"') do set difference=%%t
REM *************************************************************************************
Eliezer