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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:39:23+00:00 2026-06-15T02:39:23+00:00

I am writing a dos script and I want to get the path of

  • 0

I am writing a dos script and I want to get the path of a file that is known so that the path can be used within the script to change to that directory to use the file specified and ouput log files to the same directory.

The script adds some directories to the path and changes to the required directory to execute a command using input files in the same directory. The command generates a number of files that are saved to the same directory.

Here is what i have so far

@ECHO OFF

:: Check argument count
set argC=0
for %%x in (%*) do Set /A argC+=1

IF %argC% LSS 3 (echo WARNING must include the parent Directory, the filename and the timestep for the simulation)

:: Assign meaningfull names to the input arguments
set parentDirectory=%1
set filename=%2
set scenarioTimestep=%3

:: Check validaty of the input arguments
:: TODO: implement check for directory, filename exists, and possibly limits to the timestep 
IF "%parentDirectory%"=="" (
    set parentDirectory=P:Parent\Directory
) 
IF "%filename%"=="" (
    set filename=ship2.xmf
) 
IF "%scenarioTimestep%"=="" (
    set scenarioTimestep=0.1
) 

echo parent Directory: %parentDirectory%
echo filename: %filename%
echo timestep: %scenarioTimestep%

set MSTNFYURI=file:mst.log
set MSTNFYLEVEL=debug
set MSTNFYFLUSH=1

set XSFNFYURI=file:xsf.log
set XSFNFYLEVEL=debug
set XSFNFYFLUSH=1

set parentNFYURI=file:parent.log
set parentNFYLEVEL=debug
set parentNFYFLUSH=1

:: Add the parent directories to the path
set PATH=%parentDirectory%\bin\;%parentDirectory%\bin\ext\;%parentDirectory%\bin\gtkmm\;%parentDirectory%\bin\osg\;%PATH%

:: Change to the target directoy
set tagetDirectory=%parentDirectory%\examples\testing_inputs
cd %tagetDirectory%

echo command will be: ft -c %filename% -T %scenarioTimestep%
::ft -c %filename% -T %scenarioTimestep%

@ECHO ON

What i want to be able to do is instead of using the hard coded directory path examples\testing_inputs for targetDirectoy, i want to be able to search for the filename supplied and change directory to that path.

I know i can get the information displayed using
“dir filename.ext /s”

DOS ouptut

Volume in drive C is OS
Volume Serial Number is XXXX-XXXX

Directory of C:\Users\Me\parent\examples\testing_input

15/11/2012   02:51 PM    <size> filename
...
...

How do i extract the directory form this info to be used within the script? Also if there is more than one file of the same name, how can i select the path based on the timestamp of the file?

  • 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-15T02:39:24+00:00Added an answer on June 15, 2026 at 2:39 am
    for /f %%F in ('dir /B /S /A:-D  filename.ext ') do set file_path=%%F
    pushd  %file_path%\..
    dir_path=%CD%
    popd
    echo %file_path%
    echo %dir_path%
    

    is this what you looking for?

    EDIT: Check dbenham’s comment.

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

Sidebar

Related Questions

I'm writing a dos-batch in which I need to change the PATH . I'm
I'm writing a program for DOS and I want to get keyboard input. The
I want to save space when writing my data to file. That is I
Writing a script that cds into another dir, loads the correct rvm rvmrc file,
I want to get the same functionality in a script I'm writing as re-sign.jar
I'm writing a dos batch script and one thing I want to do is
I am writing a simple DOS utility that uses the findstr utility to search
Like the old DOS way of creating a file by writing copy con foo.txt,
Writing htaccess that allows me to remove index.php from the URL can confuse search
I have a situation while writing a dos batchs script. A tool I am

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.