@echo off : PARAMETER PASSING EXERCISES : TO RUN: : pass_param.bat "C:\Temp\dos_test.bat" :http://windowsitpro.com/article/articleid/13443/how-do-i-pass-parameters-to-a-batch-file.html :When you call a batch file, you can enter data after the command that the batch file :refers to as %1, %2, etc. For example, in the batch file hello.bat, the following command :clear the screen cls :http://talk.bmc.com/blogs/blog-gentle/anne-gentle/dos-timestamp-tips/view?searchterm=batch :create variable to hold yyyymmdd info by using substring function set yyyymmdd=%date:~10,4%%date:~4,2%%date:~7,2% :clear current log and start with the following line (single >) echo %date% %time% Starting script > %log% :set the file log with the same name as this bat file set log=%~n0.%yyyymmdd%.log echo %date% %time% CREATED LOG FILE: %~n0.%yyyymmdd%.log >> %log% echo. echo %date% %time% CURRENT FILE RUNNING: %~nx0 echo %date% %time% CURRENT FILE RUNNING: %~nx0 >> %log% echo. :All the parameters in action @echo off echo %date% %time% passed in parameter %1 echo %date% %time% fully qualified name %~f1 echo %date% %time% drive %~d1 echo %date% %time% path %~p1 echo %date% %time% filename %~n1 echo %date% %time% file extension %~x1 echo %date% %time% short filename %~sn1 echo %date% %time% short file extension %~sx1 echo %date% %time% drive and directory %~dp1 echo %date% %time% filename and extension %~nx1 REM Prompt the user for something... set /P myvar=Would you like to add something? echo. echo Thanks! echo. echo You entered %myvar% echo. echo %date% %time% %myvar% >> %log%
Friday, July 11, 2008
MS-DOS stuff, tips, notes, etc
Ok, this is really old school to be working in DOS, but just in case I ever need it again...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment