Create output file named using date and time???

  • Thread starter Thread starter numismatic
  • Start date Start date
N

numismatic

I've done this before, but can't recall or find how it's done (it's
been a few years).

I want to run a command (psservice) and redirect output to a file
using the current date and time.

for example:

psservice query ms >> "%UserProfile%\Desktop\msservices - %date%.txt"

I know I've done this before fairly simply. Any ideas?
 
I've done this before, but can't recall or find how it's done (it's
been a few years).

I want to run a command (psservice) and redirect output to a file
using the current date and time.

for example:

psservice query ms >> "%UserProfile%\Desktop\msservices - %date%.txt"

I know I've done this before fairly simply. Any ideas?

or:

psservice query ms >> "%UserProfile%\Desktop\msservices - "%date
%".txt"

returns a file named "msservices - Tue"...no .txt or the full date.
 
numismatic said:
I've done this before, but can't recall or find how it's done (it's
been a few years).

I want to run a command (psservice) and redirect output to a file
using the current date and time.

for example:

psservice query ms >> "%UserProfile%\Desktop\msservices - %date%.txt"

I know I've done this before fairly simply. Any ideas?

The variable %date% resolves to something like
Tue 05/06/2008
which contains forward slashes. None of the MS operating
systems ever released allowed any kind of slash in its file names.
You must get rid of them, eg. like so:
@echo off
set MyDate=%date:/=-%
psservice query ms >> "%UserProfile%\Desktop\msservices - %MyDate%.txt"

I don't run psservice.exe on my machine, hence I cannot tell if
the syntax for this command is correct.
 
Back
Top