January 23, 2013

Windows CMD - Useful (#005)

Count lines in multiple files using Windows command prompt

for %G in (*.sql) do find /c /v "~~~" %G

Source: http://ora-00001.blogspot.ca/2011/07/count-lines-in-multiple-files-using.html






Add date and time to log files created from Windows command prompt

:: change window's title
TITLE date_in_a_file_name

:: print current date and time
ECHO current_date: %date%
ECHO current_time: %time%

@echo off
:: format of date is YYYYMMDD
SET currdate=%date%
SET dd=%currdate:~7,2%
SET mm=%currdate:~4,2%
SET yyyy=%currdate:~10,4%
SET yyyymmdd=%yyyy%%mm%%dd%

:: format of time is HHMiSS
SET currtime=%time%
SET hh=%currtime:~0,2%
SET mi=%currtime:~3,2%
SET ss=%currtime:~6,2%
SET hhmiss=%hh%%mi%%ss%
SET hhmiss=%hhmiss: =%

ECHO test_string > C:\result_file_with_a_date_%yyyymmdd%_%hhmiss%.log



No comments:

Post a Comment