In DOS, like SET / P with a line starting with spaces

I want to get this result in a DOS package:

==> Please enter your filename, formatted as
    [user][PC_id] : 

allows the user to enter a file name after ":"

I tried many combinations, but the best I can get with

ECHO --^> Please enter your filename, formatted as
Set /P FILE=[user][PC_id] :

(spaces before "[" are not displayed)

+3
source share
3 answers

You have problems with the feature introduced in Vista / Win7.
It breaks all whitespace before the string when used set/p.

But in your case it’s easy, since you want to repeat two lines.

@echo off
setlocal EnableDelayedExpansion
set LF=^


set /p "file=--> Please enter your filename, formatted as!LF!    [user][PC_id]"
+3
source

jeb . , , . , , .

@echo off
setlocal
:: Define BS to contain a backspace
for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "BS=%%A"

::Only need %BS% if you know prompt starts at line beginning
Set /P "FILE=%BS%    [user][PC_id] : "

::If prompt is not at line beginning then need an extra char before %BS%
<nul set /p "=Part1"
<nul set /p "=.%BS%    Part2"
+2

another variant:

exit | cmd /k prompt -$G Please enter your filename, formatted as$_$s$s$s[user][PC_id]$s
set /p FILE=

echo %FILE%
+2
source

All Articles