Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I want to extract the absolute path of the current directly into a variable so I can use it in a batch file. I was wondering if there was a command in MS-DOS that is analogous to pwd in UNIX.
Here's the possible contents of my batch file:
set myVar=
start /D%myVar%\agent\src\agent.exe %myVar%\agent\src\agent.iniThanks
Eric

This should do it:
::getdir.bat
@echo off
cd> out.txt
echo.>> out.txt
date out.bat
echo SET MYVAR=%%4> enter.bat
call out.bat
del out.bat
del enter.bat
del out.txtIt will only work in a english dos, but can be adapted to any other language
-- Secret_Doom --
email: secret_doom@hotmail.com

I am confused. I want to set a variable to contain the pathname of the current directory, so why do I need to run date? Anyways I tried running this and I didn't work (first it complains that "The system cannot accept the date entered...").
Btw, if it makes a difference I am running my batch file in WinNT.
Thanks
Eric

I dont know why I'm saying this...
There's another way:
dir |find "Folder"> out.bat
echo SET MYVAR=%%2> folder.bat
call out.bat
del out.bat
del folder.batthat's simpler ;)
I'm just not sure of the word "folder" at the first line... The problem is that my dos is in another language
but I think that's it

Sorry about that! It's this F***ING forum that doesn't display the lessthan character...
here the right way of doing the first process:
::getdir.bat
@echo off
cd> out.txt
echo.>> out.txt
date [lessthan] out.bat
echo SET MYVAR=%%4> enter.bat
call out.bat
del out.bat
del enter.bat
del out.txt[lessthan] means the lessthan character (opposite of ">")
anyway, you'd better take the second process
-- Secret_Doom --

The second method doesn't work for me. Here's what I put in my batch file:
dir |find "Folder"> out.bat
echo SET anda=%%2> folder.bat
call out.bat
del out.bat
del folder.bat
start /D%anda%\gui\runtime\ startserver.batand here's what I get when I run it:
D:\AndaEms\anda\EMS>start-ems.bat
D:\AndaEms\anda\EMS>dir | find "Folder" 1>out.bat
D:\AndaEms\anda\EMS>echo SET anda=%2 1>folder.bat
D:\AndaEms\anda\EMS>call out.bat
D:\AndaEms\anda\EMS>del out.bat
D:\AndaEms\anda\EMS>del folder.bat
D:\AndaEms\anda\EMS>start /D\gui\runtime\ startserver.bat
The system cannot find the file startserver.bat.D:\AndaEms\anda\EMS>

Sorry again. I said I weren't sure about the first line of second process... It is wrong.
Here the right way:dir |find "Directory"> out.bat
echo SET MYVAR=%%2> directory.bat
call out.bat
del out.bat
del directory.batThat's it. I think it won't work in pure dos, only in a windows box
if you're in pure dos, use that first process (that one involving date)-- Secret_Doom --

Hi. It seems like I encountered another problem. The working solution (the last one posted by Secret_Doom) works for pathnames that doesn't have whitespaces in it, but it doesn't work for ones w/ whitespaces. Pathname that start under "D:\Program Files\..." is one such example.
There are two problems:
"echo SET MYVAR=%%2> directory.bat"
1). When SET tries to read of the pathname from out.bat, it only looks at the third item in the file (%2). But if the filename contains one or more spaces then this would only get the first part of the filename.
2). I want to use the extracted pathname to set the working directory when I call "start" but "start" doesnt seem to take any filename with spaces, nor would it take filenames that are quoted.
eg. start /DD:Program Files..... or
start /D"D: Program Files..."How can I go around these problems?
The only thing I can think of is to set the pathname as a compacted form (used in windows dos) such as D:Progra~1\ for D:Program Files\.
Btw, I am trying to do this in Windows Dos.Thanks
Alick!

Hi there!
Try this one: (the numbers aren't part of it, they're just for helping on line wrapping)OO. SET MYVAR=
01. dir |find "Directory"> out.bat
02. echo :loop> directory.bat
03. echo SHIFT>> directory.bat
04. echo if "%%1"=="" goto end>> directory.bat
05. echo if not "%%myvar%%"=="" SET MYVAR=%%MYVAR%% %%1>> directory.bat
06. echo if "%%myvar%%"=="" SET MYVAR=%%1>> directory.bat
07. echo goto loop>> directory.bat
08. echo :end>> directory.bat
09. call out.bat
10. del out.bat
11. del directory.batThat should solve your problem.
Please keep me informed of your progress!!!-- Secret_Doom --
email: secret_doom@hotmail.com

![]() |
need to restore backup di...
|
Need DOS Help Please!!!!
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |