The Woo
The Woo

Reputation: 18645

Batch File Creating Text File With Date

I have a batch file to run a defrag on a computer - as below. At the moment it is creating the text file named ComputerName.txt

@echo off

defrag.exe c: -f -v >"C:\Defrag\ComputerName.txt"

How can I get the date to also ammend to the end of the text file? IE:

ComputerName.2011.02.08.txt

Upvotes: 2

Views: 2801

Answers (1)

Peon the Great
Peon the Great

Reputation: 1319

for /f "tokens=2-4 delims=/- " %%A in ('date /T') do set var=c:\defrag\ComputerName.%%C.%%A.%%B.txt

defrag c: -f -v > %var%

Upvotes: 1

Related Questions