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

  • SEARCH
  • Home
  • 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 4078624
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:41:51+00:00 2026-05-20T17:41:51+00:00

The FOR command in Windows has some options that it did not have in

  • 0

The FOR command in Windows has some options that it did not have in DOS. Specifically, it supports returning filename segments as follows.

  In addition, substitution of FOR variable references has been enhanced.
  You can now use the following optional syntax:

  %~I         - expands %I removing any surrounding quotes (")
  %~fI        - expands %I to a fully qualified path name
  %~dI        - expands %I to a drive letter only
  %~pI        - expands %I to a path only
  %~nI        - expands %I to a file name only
  %~xI        - expands %I to a file extension only
  %~sI        - expanded path contains short names only
  %~aI        - expands %I to file attributes of file
  %~tI        - expands %I to date/time of file
  %~zI        - expands %I to size of file

When I try to use the following command, it does not work. Instead of printing \Program Files, it prints \.

  for %i in ("%programfiles%") do echo %~pi

It seems that only the p argument is incorrect because the other arguments return the expected results.

  > for %i in ("%programfiles%") do echo %i
  C:\Program Files

  > for %i in ("%programfiles%") do echo %~i
  C:\Program Files

  > for %i in ("%programfiles%") do echo %~fi
  C:\Program Files

  > for %i in ("%programfiles%") do echo %~is
  C:\PROGRA~1

  > for %i in ("%programfiles%") do echo %~id
  C:

Does anyone know what the problem could be?

  • 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-20T17:41:52+00:00Added an answer on May 20, 2026 at 5:41 pm

    This is not a problem, this is the correct and expected result. ~p extracts the path part of a given filespec.

    In this case

    • c: is the drive, returned by %~di;
    • \ is the path, returned by %~pi;
    • Program Files is the name, returned by %~ni;
    • and C:\Program Files is the complete expanded filespec, returned by %~fi, or by %~dpnxi.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason the Windows command prompt is special in that you have to
Is there a better windows command line shell other than cmd which has better
A Windows process created from an exe file has access to the command string
Is there a Windows command that will output the size in bytes of a
I've got a PHP script which I'm running from a command line (windows) that
I would like to pass some options to a compiler. The option would have
I have been getting this error for quite some time now and Google has
There is a netsh and a route command on Windows. From their help text
I am writing a batch file script using Windows command and want to change
Is there a way to emulate the unix cut command on windows XP, without

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.