-2

I have to create a batch file but before entering a command it should display like:

C:\user\nameofuser AND the current date>

I can only display the date with echo %date%, but cannot make it stay on the left.

How to reach my aim?

atline
  • 28,355
  • 16
  • 77
  • 113
fryx
  • 29
  • 4
  • 1
    That's trivial: see `help prompt` and guess what `$D` is for. `prompt $P$S$D$G$S` –  Jan 04 '19 at 20:10
  • Or if taking `C:\user\nameofuser` literal and constant (**not** changing with current dir) : `prompt %USERPROFILE%$S$D$G$S` –  Jan 04 '19 at 20:22

1 Answers1

1

If you want that, then it so easy with the prompt command, which defines the cmd.exe command prompt. The default is $P $G. You should change to $P (Current drive and path ) $S (space) $D (current date) $G (greater-than sign) and optionally a space with $S.

Changing command prompt requires the use of prompt command. Use prompt $P$S$D$G$S. The $S is optional.

Also, if you don't want to continuously change your prompt with the newest drive and path (not recommended), include %userprofile% environment variable instead of $P.

If you don't want the name of the date this can be done, hard of course, you may want a continuous loop, take a look at

If you don't want the date name you can see How do I get current datetime on the Windows command line, in a suitable format for using in a filename?, but you may want a continuous loop.

Take a look below:

$A & (Ampersand)
$B | (pipe)
$C ( (Left parenthesis)
$D Current date
$E Escape code (ASCII code 27)
$F ) (Right parenthesis)
$G > (greater-than sign)
$H Backspace (erases previous character)
$L < (less-than sign)
$N Current drive
$P Current drive and path
$Q = (equal sign)
$S (space)
$T Current time
$V Windows version number
$_ Carriage return and linefeed
$$ $ (dollar sign)

From prompt /? in cmd

double-beep
  • 5,031
  • 17
  • 33
  • 41