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 8958693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:16:22+00:00 2026-06-15T15:16:22+00:00

So my many attempts to search for a solution have resulted in a million

  • 0

So my many attempts to search for a solution have resulted in a million ways to find the folder of the bat file being executed, however what I am looking to do is find the folder for the filename being passed to the bat file.

Example:

C:\Temp\runthis.bat "C:\Blah\Ah Argh\rage.txt"

I want to get a string within that bat file that is simply “C:\Blah\Ah Argh\”, alternatively I would also be able to work with getting a string of “rage.txt”

Editing to explain why: Looking to check for the filename within another txt file which is the directory listing of a ftp server to verify that a file successfully uploaded to it. Then if successful I need to move the file to a subfolder of the original folder \uploaded\ but we have many of these folders setup so I can’t hard code it.

Thanks

  • 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-06-15T15:16:23+00:00Added an answer on June 15, 2026 at 3:16 pm
    @echo off
    if %1X==X echo Syntax: %0 "path"
    
    rem  The for loop doesn't actually loop. You can split strings with it, but in 
    rem  this case we don't. So there is only one iteration in which %%X will 
    rem  contain the full path.
    
    rem  Pass it %1, which is the first parameter. Note the quotes, which are 
    rem  required if you don't add quotes around the parameter and optional (but 
    rem  still valid) when you do.
    
    for /F "delims=|" %%X in ("%1") do (
    
      rem  FOR LOOP variables can be used with certain modifiers, preceeded by a 
      rem  tilde. In this case I'm using d and p, which stand for drive and path,
      rem  effectively trimming the file name from the path.
    
      echo %%~dpX
    
      rem The ~n modifier selects the file name only. ~x is for extension
    
      echo %%~nxX
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have had many attempts now on attempting to make this work and i
Continuation of: Standalone Cross Platform (Windows/Linux)) File Compression for C/C++? After many attempts on
I need to keep track of how many failed attempts have been made to
I want to do a search across 2 tables that have a many-to-one relationship,
I have seen many attempts at a cross-browser @font-face syntax including the: Bulletproof @font-face
many Places in the sample code i have seen 2 different way of @synthesize
Many threads have access to summary . Each thread will have an unique key
Many search engines are not using meta keywords and Google through many recent updates
After many attempts to crack this I am stuck so I turn to SO
PDO with MySQL; PHP v. 5.2.14 I have a search form with a text

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.