Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 605509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:09:13+00:00 2026-05-13T17:09:13+00:00

The following command in a batch file does not work as expected/hoped: echo %~nxs1

  • 0

The following command in a batch file does not work as expected/hoped:

    echo %~nxs1

Here is a sample display of what I’m trying to get:

C:\>type test.bat
@dir /b %1
@echo %~nxs1

C:\>test "C:\Documents and Settings\All Users\ntuser.dat"
ntuser.dat
NTUSER.DAT

C:\>test "C:\Documents and Settings\All Users\ntuser.data"
ntuser.data
NTUSER~1.DA~

C:\>test "C:\Documents and Settings\All Users\ntuser.dat.baz"
ntuser.dat.baz
NTUSER~1.BAZ

C:\>test "C:\Documents and Settings\All Users\foo.bar.baz"
File Not Found
foo.bar.baz (or FOO~1.BAZ or whatever, doesn’t really matter since
             file does not exist, though latter would be nice)

Instead what I get is something like the following (depending on assigned short-filenames):

C:\>type test.bat
@dir /b %1
@echo %~nxs1

C:\>test "C:\Documents and Settings\All Users\ntuser.dat"
ntuser.dat
s\ntuser.dat

C:\>test "C:\Documents and Settings\All Users\ntuser.data"
ntuser.data
s\ntuser.data

C:\>test "C:\Documents and Settings\All Users\ntuser.dat.baz"
ntuser.dat.baz
z

C:\>test "C:\Documents and Settings\All Users\foo.bar.baz"
File Not Found
s\foo.bar.baz

Basically, I need to pass a filename to a BAT file and have the script get (eg display) it as a short-filename, but only the filename and extension, no drive or path.

The help info for FOR gives %~fsI as an example, but that has the whole path as a short-filename, not just the file. Does anyone know how to combine the S parameter from %~ without getting the whole path?

Thanks a lot.

Updates

  1. I am not looking for a solution in a different language, I need the BAT command to work.

  2. It seems that it works for others, so I am checking to see if it is some kind of alternate configuration issue. I’m currently testing to see if Command Processor Extensions could be the cause.

  3. It won’t work at all if Extensions are disabled (obviously), so I’m going on the hypothesis that it is a bug that was fixed in a subsequent service pack (the system I tested on is XP SP1). I’m testing SP2 and SP3 today…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:09:13+00:00Added an answer on May 13, 2026 at 5:09 pm

    Well I just confirmed it. I tested the script with CMD.EXE from XP SP1, SP2, and SP3 as well as an SP2 VM installation. It gave the aforementioned erroneous results with the SP1 version, but worked correctly in the SP2 and SP3 versions. So it is indeed a bug that was fixed. For anyone else who runs into this, the CMD.EXE file from SP2+ can be dropped into an SP1 installation without issue (assuming that an update is not feasible).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 304k
  • Answers 304k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I wasn't able to find a way around it. Support… May 13, 2026 at 8:54 pm
  • Editorial Team
    Editorial Team added an answer When using a glob pattern, a question mark represents a… May 13, 2026 at 8:54 pm
  • Editorial Team
    Editorial Team added an answer Auto Increment Ids There are auto-increment id generators available for… May 13, 2026 at 8:54 pm

Related Questions

Howdy, I'm writing a batch script that will run on a Windows XP machine.
Update: Check out this follow-up question: Gem Update on Windows - is it broken?
I have a nightly build DOS batch script that invokes devenv.exe to build a
I would like to know a way of deleting a read only file using
I am having an issue with the Microsoft Visual Sourcesafe command line options that

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.