4

I made a bat file and during execution, it displays a title in the command window.

The title includes the bat filename, and it is displayed in full, including the .bat extension.

The code I'm using to do this is shown below (see the Title command on the 5th line).

The names I have used:

  • Filename: Facebook.bat
  • Title (line 5): Hacking %~nx1 Called Domain which outputs Hacking Facebook.bat Called Domain in the title-bar.

I want the title-bar to read Hacking Facebook Called Domain.

How do I do this?

My bat file:

@echo off
color 0d
call :sub *.bat
:sub
Title Hacking %~nx1 Called Domain
echo Test 1
timeout /t 2
echo Test 2
timeout /t 2
echo Completed
timeout /t 2
exit

enter image description here

Kevin Panko
  • 7,346
  • 22
  • 44
  • 53
Ferit Uzun
  • 59
  • 1
  • 4

1 Answers1

10

The screenshot made the question much more clear.

I see you're using %~nx1 to show the filename in the title of the command prompt that shows up.

To use the filename without the extension, instead of using %~nx1, use %~n0.

ie:

@echo off
color 0d
call :sub *.bat
:sub
Title Hacking %~n0 Called Domain
echo Test 1
timeout /t 2
echo Test 2
timeout /t 2
echo Completed
timeout /t 2
exit

I got %~n0 from here.

ᔕᖺᘎᕊ
  • 6,173
  • 4
  • 33
  • 45