TheBugSlayer
Programmer
Hi guys,
There is a SQL Server job that deletes log files older than X number of days. It executes a DOS command that loops through all files that match the criteria, prints the command and executes it (DELete).
There are parts of the syntax that I don't understand such as the 2^>^&1 characters in the ForFiles command.
I know this sounds more like a DOS\Windows CMD question but since it's executed in SQL Server I thought some conversant admin could help me understand the whole thing here. The parameters too are a source of mystery (%V).
See the command below.
Thank you.
MCP SQL Server 2000, MCTS SQL Server 2005, MCTS SQL Server 2008 (DBD, DBA), Training HOTT cert SQL Server 2012 Business Intelligence (SSIS, SSAS).
There is a SQL Server job that deletes log files older than X number of days. It executes a DOS command that loops through all files that match the criteria, prints the command and executes it (DELete).
There are parts of the syntax that I don't understand such as the 2^>^&1 characters in the ForFiles command.
I know this sounds more like a DOS\Windows CMD question but since it's executed in SQL Server I thought some conversant admin could help me understand the whole thing here. The parameters too are a source of mystery (%V).
See the command below.
Code:
cmd /q /c "For /F "tokens=1 delims=" %v In ('ForFiles /P "G:\SQLData\MSSQL11.MSSQLSERVER\MSSQL\LOG" /m *_*_*_*.txt /d -30 2^>^&1') do if EXIST "G:\SQLData\MSSQL11.MSSQLSERVER\MSSQL\LOG"\%v echo del "G:\SQLData\MSSQL11.MSSQLSERVER\MSSQL\LOG"\%v& del "G:\SQLData\MSSQL11.MSSQLSERVER\MSSQL\LOG"\%v"
Thank you.
MCP SQL Server 2000, MCTS SQL Server 2005, MCTS SQL Server 2008 (DBD, DBA), Training HOTT cert SQL Server 2012 Business Intelligence (SSIS, SSAS).