Computing.Net > Forums > Disk Operating System > Can I do this in MS-DOS?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Can I do this in MS-DOS?

Reply to Message Icon

Name: Eric
Date: July 2, 2001 at 20:43:09 Pacific
Comment:

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.ini

Thanks

Eric



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: July 2, 2001 at 20:51:24 Pacific
Reply:

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.txt

It will only work in a english dos, but can be adapted to any other language

-- Secret_Doom --

email: secret_doom@hotmail.com


0

Response Number 2
Name: Eric
Date: July 2, 2001 at 21:13:16 Pacific
Reply:

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


0

Response Number 3
Name: Secret_Doom
Date: July 2, 2001 at 21:13:17 Pacific
Reply:

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.bat

that'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


0

Response Number 4
Name: Secret_Doom
Date: July 2, 2001 at 21:20:05 Pacific
Reply:

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 --


0

Response Number 5
Name: Eric Yip
Date: July 3, 2001 at 10:38:19 Pacific
Reply:

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.bat

and 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>


0

Related Posts

See More



Response Number 6
Name: Secret_Doom
Date: July 3, 2001 at 13:50:08 Pacific
Reply:

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.bat

That'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 --


0

Response Number 7
Name: Eric Yip
Date: July 5, 2001 at 12:49:38 Pacific
Reply:

The last one works. Many thanks.

Alick!


0

Response Number 8
Name: Eric Yip
Date: July 9, 2001 at 12:12:51 Pacific
Reply:

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!


0

Response Number 9
Name: Secret_Doom
Date: July 9, 2001 at 19:57:04 Pacific
Reply:

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.bat

That should solve your problem.
Please keep me informed of your progress!!!

-- Secret_Doom --

email: secret_doom@hotmail.com


0

Sponsored Link
Ads by Google
Reply to Message Icon

need to restore backup di... Need DOS Help Please!!!!



Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Can I do this in MS-DOS?

I can't restart in MS-DOS mode www.computing.net/answers/dos/i-cant-restart-in-msdos-mode/3289.html

Can not change directory in ms-dos... www.computing.net/answers/dos/can-not-change-directory-in-msdos/10453.html

Games have sound in Win95 but none in MSDOS mode. What can I do???? www.computing.net/answers/dos/games-have-sound-in-win95-but-none-in-msdos-mode-what-can-i-do/56.html