Equivalent 9XDos code to NT Find bat/cmd path %~dp0

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ispy
Posts: 16
Joined: 25 Dec 2020 15:36

Equivalent 9XDos code to NT Find bat/cmd path %~dp0

#1 Post by ispy » 25 Dec 2020 16:26

Hi All :D ,
Hope someone can help me a question that has been bugging me for a while now I will try to explain:
In NT.x cmd it comes with an internal syntax that you can use which allows you to, for want of a better expression findyourselfbat/cmd script "%~dp0"
I do Not fully understand how this script works but is very useful in cmd batch scripting (I Do not think it can be used from the commandline though) for establishing the path to your running batch script & has the perculiar syntax of missing the trailing backslash just for e.g %~dp0<No Backslash>something. bat - or actually typed - %~dp0something.bat.
Now if I revert to 9xdos & try to use the script it will fail, does anyone know of equivalent code that can be used in a 9xdos situation that does the same thing please? The nearest thing I have been able to uncover is this code but again I'm a bit thick I don't understand it. See below
%0\
cd %0\.. (--> yes after the backslash it is dot dot)
'..\' = removes the path component that precedes it
Apparently & as I am led to believe if using in NT you have the option of the '/d' flag like so (Because it can [unless someone tells me not] the %0\ can be used in NT & 9xdos)
cd /d %0\.. (Only NT cannot be used in 9Xdos)
Can you use this "%0\" at the commandline as well as in batchfile, what are its limitations please, if you can use it in batchfile would you use %%0\ (Double percentages for example) & if you had a path for example with spaces in it like c:\program files is there any way to enclose the script in double quotes "". Can someone give me some examples of how you would use this code please? like for instance in NT you could do this set a variable to the batchfiles directory like
SET Mypath=%~dp0
echo %Mypath%
Sorry for all the questions & my lack of understanding but can someone instruct me please?
Thanks in advance
ispy :D

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Equivalent 9XDos code to NT Find bat/cmd path %~dp0

#2 Post by penpen » 28 Dec 2020 10:41

On older command environments, you typically either have to use debug.exe, qbasic.exe or you have to make an own temporary batch script to perform your tasks.

The command line parameter "%0" won't always give you the path. It only contains the first token (~= meaningfull part) string used to execute your batch file, so it easily could contain the filename of your batch script with no extension.


This following (untested; would have to setup a new virtual win9x) batch might help you; file "test.bat":

Code: Select all

@echo off
if "%1" == "" goto :main
goto :%1


:createTmp
prompt set dir$Q$P$_:
@echo on
echo :echo ok
@echo off
prompt $p$G
goto :eof


:setDir
if exist tmp.bat del tmp.bat
>"%tmp%\tmp.bat" command.com /c %0 createTmp
call "%tmp%\tmp.bat"
del "%tmp%\tmp.bat"
goto :eof


:main
call %0 setDir
echo dir=%dir%
goto :eof


:eof

See "<command name> /?" for more info.


penpen

Edit: Added missing "goto :eof".
Edit2: Replaced recalling of actual file with %0 instead of its name and use system temporary directory in case of write protection of work directory.

ispy
Posts: 16
Joined: 25 Dec 2020 15:36

Re: Equivalent 9XDos code to NT Find bat/cmd path %~dp0

#3 Post by ispy » 28 Dec 2020 15:54

@Penpen,
Firstly can I take this opertunity to thank you for your response to my posting. I am really grateful! Can I ask for your further help please?

Oh so "%0" is the name of my Batch script not the path & as you rightly say could give unpredictable results. I have managed to use the script in a batchfile and it reports back a SFN format path in this case "c:\My Documents" was printed to screen C:\MYDOCU~1\TEST.BAT. I deliberately used My Documents to see what it printed to screen in respect of the space between My & Documents.
My setup is as follows for background info: Windows XPSP3 Host with portable VBox with guest OS Windows 98SE I cannot get the shared folder setup which makes it difficult in sharing files but although a tad slow is good for testing.
I have tried your TEST.BAT file as per your script code but it printed on screen - Bad Command or file name (on the next line it states) dir=
If it is not too much trouble could you give an outline of what the script is trying to achieve for my understanding please?

In Win9Xdos would you need to add additional characters to "%0" to make it produce an equivalent to NT's "%~dp0" as this does not work in win9X/Dos7.1 I suppose you would need to remove the name of the batfile & that could as you say leave you with nothing. So what does "CD %0\.." mean in laymans terms I know CD = Change Dir. One website stated "..\" removes the path component that precedes it, in this case the batfile itself.

Again Many thanks for your participation
Best Regards,
David

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Equivalent 9XDos code to NT Find bat/cmd path %~dp0

#4 Post by penpen » 30 Dec 2020 07:48

ispy wrote:
28 Dec 2020 15:54
I have tried your TEST.BAT file as per your script code but it printed on screen - Bad Command or file name (on the next line it states) dir=
I missed a "goto :eof" in the above code. I added and tested the result on win98SE, so that code should work now.

ispy wrote:
28 Dec 2020 15:54
could you give an outline of what the script is trying to achieve for my understanding please?
The idea is to create a temporary batch file that assigns the actual path to an environment variable.
This is done in three steps.

In function ":createTemp", the content of that temporary batch file is echoed by changing the user prompt message and use the echo-command to output that to stdout.
In ":setDir", the above created output is redirected to the file "tmp.bat". Note that the command-echo (the prompt message and the command-string that will be executed) and the output of the echo-command are in different instances so one have to use a common parent instance to redirect both outputs into a file (hence the "command /c" line).

ispy wrote:
28 Dec 2020 15:54
So what does "CD %0\.." mean in laymans terms I know CD = Change Dir. One website stated "..\" removes the path component that precedes it, in this case the batfile itself.
I'm not sure what might be unclear to you, you explained that line:
"%0" is replaced with the specified application name, which could be a full, relative or partial path string (ex: "C:\doo\foo.bat", "doo\foo.bat", or "foo").
The cd-command processes "\.." to alter the path to the parent element (ad ex: "C:\doo", "doo", or "") and then changes the directory to the resulting path.


penpen

Eureka!
Posts: 137
Joined: 25 Jul 2019 18:25

Re: Equivalent 9XDos code to NT Find bat/cmd path %~dp0

#5 Post by Eureka! » 30 Dec 2020 14:29

maybe the TRUENAME command can help you here.
Something like: TRUENAME %0 or even TRUENAME %0\..

(but memory is vague; maybe truename wasn't even in Win98)

ispy
Posts: 16
Joined: 25 Dec 2020 15:36

Re: Equivalent 9XDos code to NT Find bat/cmd path %~dp0

#6 Post by ispy » 31 Dec 2020 10:44

Hi Penpen & Eureka,
Many thanks for sharing your knowledge firstly...
@Eureka - I tried to use the truename as outlined here:
https://www.robvanderwoude.com/truename.php - but it only returns the same information in SFN format C:\MYDOCU~1\ZERO.BAT. I have thought of piping the output through ODI's LFN tools (LCD) but even "if" it was successful the remaning \ZERO.BAT of the path would need editing e.g. removal somehow so in conclusion the "%0" is prooving not user friendly to me. I even tried to run "%0" in XP CMD & it bombed out in various combinations when the website stated it was usable in NT.
@ Penpen - Many thanks for your explanation re cd %0 easier to understand laid out as you have kindly interpreted. Tried again with the Test.bat with the goto :eof it came back with the same error message as original, there must be something wrong with the way my system is setup cuz if you have tested & is OK, mine still fails? The only way I could get the script to work that is no error message (& the line 'dir=' ) was to edit line 3 of your script with to goto :eof instead of goto :%1 ?

The only course of action left is to use CD (Change Directory) without any parameters & will need to ensure the operation is undertaken in the same path as the batchfile currently resides in respect of 9XDos.
So it looks like there is no alternative in 9XDos to %~dp0 in NT unless you are prepared to goto great lengths to achieve it.

Best Regards,
David

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Equivalent 9XDos code to NT Find bat/cmd path %~dp0

#7 Post by penpen » 31 Dec 2020 17:55

I made two changes, that might help in some circumstances (in case command.com doesn't use current work directory - for whatever reasons; and in case of a possible write protection in the current directory).
You should check, if the environment variable TMP is initialized correctly (to a path with read/write permission).


penpen

Edit: In case you prefer the output of "truename.exe" Eureka! suggested, you may use debug.exe.

ispy
Posts: 16
Joined: 25 Dec 2020 15:36

Re: Equivalent 9XDos code to NT Find bat/cmd path %~dp0

#8 Post by ispy » 01 Jan 2021 06:33

@Penpen
Yep - Many thanks the what I now call the Penpen.bat compiled from your code now works & might I add with LFN format, Great Job!
Your quote - You should check, if the environment variable TMP is initialized correctly (to a path with read/write permission). Ans not sure how you do this but would appreciate instruction. My 98SE Guest OS is setup in Virtual box Host OS XPSP3?
I have added one more line to your code, at my end in the form of, After label :createTmp I've inserted SET Dir= just to clear any previous set commands before commencement but yes it works & with no third party utils. Could this be adapted into a for-in-Do to condense possibly?

Just a little background info to set the backdrop of what I am trying to achieve namely to generically with limitations setup a small XMSDSK @ Z: in order to process any temp files, scripts etc which upon completion will be unloaded to setup a CWD (Current Working dir) variable that can be used from say Dos 6.x up to win7 CMD. The ramdisk is workaround for just in case the user tries to start the process from read-only media. Then using Ver & find check on the users OS & then branch via goto labels to identify the OS, with error output message if not applicable to that OS. Once OS identified compile variable %CWD% & Exit. Now the above is the generic version where the user in a given scenario might not know the OS installed. In addition I would create smaller scripts for situations where the OS is known possibly with or without the Ramdisk (possibly do a test for READ-only) option to condence. Then I was then thinking of converting the batchfiles into .com/.exe format to be called CALL or Start with one caveat the batch/exe/com must be in the dir where the "users" batch/Script operates & an instruction to perform cleanup upon completion of the users batch/script code.

Why you might ask - Well I have always admired the %~dp0 NT find-itself code both small and effective (albeit only in batch) I am trying to take it one step further in creating a variable linked to the current CWD, ("%~dp0" into var for Various OS's with alternative batch code). This would setup a CWD from many situations kinda one step further than %~dp0 by putting %~dp0 into a variable

Your Quote - Edit: In case you prefer the output of "truename.exe" Eureka! suggested, you may use debug.exe. Ans - I think, but not 100% sure on this truename is an internal command built into 98SE & Debug to me is very interesting concept on a side note I have been playing about with a debug script which is not working to strip out the CR/LF's from a tmp txt file with the line SET CWD= then append with resultant %CWD% > ren it to bat & then CALL. I think again not sure but is referred to as "Command Substitution", all from temp files.

Just to elaborate a bit further I have found, funnerly enough on Dostips, a progey called SET2VAR.exe mentioned & (tried out) along with Horst Schaeffers LMOD the latter has the added advantake of working within 98SE & XP CMD & generates less code but larger overhead. The alternative is a batch only varient that I am currently experimenting with also not using any third party utils in LFN format. I think Dos6.x is a special case & will need a branch :Label possibly i have a code example but do not have access to Dos6.x to try out.

Sorry for the long winded cryptic explanation but there is method in my madness, if I can get it to work would for me be beneficial to noobs like me & others also. I also have looked at PUSHD & POPD but do not yet fully understand mechanics of it yet.

Best Regards,
David
Last edited by ispy on 01 Jan 2021 07:24, edited 2 times in total.

pieh-ejdsch
Posts: 240
Joined: 04 Mar 2014 11:14
Location: germany

Re: Equivalent 9XDos code to NT Find bat/cmd path %~dp0

#9 Post by pieh-ejdsch » 01 Jan 2021 06:38

If you change to another directory, a possible drive change must also be made afterwards.
I created an equivalent for Pushd and Popd in the win98 timestamp bat to create these variables (yy mm and so on).
https://administrator.de/forum/win98-ba ... ent-891359
A changing drive letter can be extracted using choice.

Phil

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Equivalent 9XDos code to NT Find bat/cmd path %~dp0

#10 Post by penpen » 05 Jan 2021 18:49

ispy wrote:
01 Jan 2021 06:33
not sure how you do this
Simply open a command prompt and type "set" (without doublequotes) and hit <ENTER>. Then check, if a an environment variable named "TMP" is there, contains a path name to a folder and then check if that folder exists and if you can create, edit and delete files in that folder.

ispy wrote:
01 Jan 2021 06:33
Could this be adapted into a for-in-Do to condense possibly?
I'm not sure how you would want to condense that. In Win9x only the most basic for-loop is defined, so no for/f-loop (if you meant to use that).

ispy wrote:
01 Jan 2021 06:33
Then I was then thinking of converting the batchfiles into .com/.exe format
I would recommend to NOT use one of the batch compiler as long as they are no 'real' compilers.
Up to now all so called "batch compilers" are doing the same:
Pack the batch and unpack it to a temporary file whenever the exe is called. Or in other words they are no compilers at all.

Not only is this no more secure, it's also less fast (unpack und delete is added to the normal execution of that batch), some "compilers" add extra lines to the batch file, which could make the batch behave unexpected (in specific cases) and some of those "compilers" even add unwanted installers and viruses... .
Not to mention that the executable is as system dependent as the original batch file.

If you want to compile a c++ source (or similar) and compile that to an executable, then that's OK.


Additional Sidenote:
I'm not sure if you like to see the debug-solution i mentioned, but just in case (i don't menat to write 16-bit programs with that - although that definitely is possible - you should search the internet for tutorials on that topic; i just meant to write the start of a batch file; untested):

Code: Select all

@goto :main skipping debug.exe script
a 100
db "set dir=$"

n tmp.bat
r bx
0
r cx
8
w
q

:main batch portion
@echo off
type t.bat | debug.exe
truename | >>tmp.bat find "\"
type tmp.bat
call tmp.bat
echo dir=%dir%
set dir=
goto :eof
type t.bat | >nul debug.exe

:eof
In Short, this is a hybrid debug-batch-script.

From the perspective of debug.exe this script does the following:
"@..." is an unknown debug command and will trigger an harmless error message.
"a 100" starts assembling at address 0x100.
"db ..." defines the bytes to write (the content of the temporary batch in this case)
<RETURN> ends the assembling
"n <filename>" advises debug to use that filename
"r <register> <value>" sets the content of the specified register (i prefer to write the value into the next line, so bx is set to 0 and cx is set to 8, which both specifies the length of the file)
"w" writes the specified size (in this case 0x00000008 == 8 bytes) of the assembly starting with the specified address to the specified file.
"q" quits debug.exe.

From the batch file "goto :main" skips the debug script.
"type t.bat | debug.exe" is piping the debug script into debug (so "t.bat" is the name of that hybrid batch - i wanted to avoid checking if %0 is the full actual filename, or if we should add an extension ".bat"...).
"truename | >>tmp.bat find "\"" then appends the output of truename.exe to the temporary batch file.
The rest should be self-explanatory.


penpen

jfl
Posts: 226
Joined: 26 Oct 2012 06:40
Location: Saint Hilaire du Touvet, France
Contact:

Re: Equivalent 9XDos code to NT Find bat/cmd path %~dp0

#11 Post by jfl » 07 Jan 2021 04:41

truename is an internal command of the command.com shell.
This is independent of DOS or Windows 98: command.com is also available in Windows XP, as an alternative to its native cmd.exe shell.
I'm pretty sure that you can even make the XP version of command.com run in 32-bits versions of Vista and later OSs.

I gave it a try in a Windows 98 VM, and indeed the 'truename %0\..' command works in a batch, and displays the batch location.
The hard problem was to capture truename's output, in the absence of a 'for /f' command, like in cmd.exe.

@penpen
Using debug for that is a great idea!
In a burst of nostalgy, I immediately tried your script in my Windows 98 VM.
It works great, but there are a few issues:
  • The last 3 lines are useless. (Leftovers from a previous version maybe?)
  • There's a chicken and egg problem in the line 'type t.bat | debug.exe':
    This assumes you know the batch is in the current directory,
    whereas the whole point of the exercise is to locate in which directory it is!
Here's a modified version that works whatever the batch name and location is.

Code: Select all

@echo off
:# Create a temporary batch, 10-bytes-long with the final CRLF
 >%TEMP%\tmp.bat echo set dir=
:# Create an input file for debug, that writes 8 bytes
 >%TEMP%\tmp.dbg echo r cx
>>%TEMP%\tmp.dbg echo 8
>>%TEMP%\tmp.dbg echo w
>>%TEMP%\tmp.dbg echo q
:# Load the temporary batch and rewrite its first 8 bytes only
 <%TEMP%\tmp.dbg debug.exe %TEMP%\tmp.bat >NUL
:# Append the true name of this batch's directory
truename %0\.. | find "\" >>%TEMP%\tmp.bat
:# Test the resulting file
type %TEMP%\tmp.bat
call %TEMP%\tmp.bat
echo dir=%dir%
set dir=
For nostalgics of command.com's truename, there's a truename.exe program for cmd.exe in my System Tools Library.
It resolves relative paths, short names, links and junctions. (The short name resolution is a great workaround for the absence of a %~l modifier to do the inverse of the %~s modifier in cmd.exe.)
And (better than the original) truename.exe has options for controlling what you want resolved or not.
Ex, to avoid resolving links, ie. just get the absolute pathname, use option -L:

Code: Select all

C:\JFL\Temp>truename t.bat
C:\Users\Larvoire\Documents\Temp\t.bat

C:\JFL\Temp>truename -L t.bat
C:\JFL\Temp\t.bat

C:\JFL\Temp>

ispy
Posts: 16
Joined: 25 Dec 2020 15:36

Re: Equivalent 9XDos code to NT Find bat/cmd path %~dp0

#12 Post by ispy » 07 Jan 2021 09:36

General comment - Apologies for not being attentive to this post but I have been distracted with other life issues lately which needed immediate attention & action

@pieh-ejdsch - Please excuse my ignorance here I'm not quite sure what you getting at here. I clicked on the link you have kindly provided as you seem to be referring to Pushd & Popd in 9X. When you goto the link it illustrates a rather large but well crafted batchfile which I assume would take a fair amount of time to run? Can you elaborate a little more as to the point you are trying to get across please?

@Penpen - Many thanks for the explanation as to how to test for "TMP" etc very useful. I kinda suspected that was the situation with For within the Win9xdos scenario. Just for a workaround for possibly others who may visit this post I have found a program by Bruce Gunthrie called Fortune which apparently adds additional functionality to the for command under win9Xdos, however within the context of this post & those contributing to this post, it may be deemed an un-neceesary overhead in terms of using yet another external program. What I have learned from this is maybe an precautionary integrity check needs to be performed to test if these TEMP/TMP are functional as this script tends to use the TMP/TEMP quite a lot?

In respect of the batch compilers point taken & understood, it's just if some of this stuff could be condensed into a single com/exe file would have possibly helped, your advice and experience are valuable in such matters?

Yes the DEBUG option is "VERY" Very interesting & debug programs or scripts can be compiled into functional com files I think if under 64Kbs if memory serves me right? In respect of the Debug Script you have provided can I share in "jfl"'s exuberance in what you have produced I would absolutely love to learn the capabilities of Debug in writing small scripts and programs & the Hybrid capability opens all sorts of additional doors, to new possibilities. It almost warrants a separate section of Dostips, Hint Hint in a sub-classication forum for people to learn & share ideas in respect of Debug & hybriding with batch along with things like this I've seen: there is also an enhanced DEBUG program called DebugX I think I first came across it in one of the Starmans web pages which is compatable with all off the existing MS Debug commands & Some.

Code: Select all

@echo off
:: ECHOO.COM program
chcp 437 >nul
echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR)EEEUYRX2Dx=>EKU.com
echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU!WvX0GwUY Wv;ovBX2Gv0ExGIuht6>>EKU.com
echo ?@xAyJHmH@=a?}VjuN?_LEkS?`w`s_{OCIvJDGEHtc{OCIKGMgELCI?GGg>>EKU.com
echo EL?s?WL`LRBcx=k_K?AxVD?fCo?Cd?BLDs0>>EKU.com
echoo $31$30$30$25$20$b4$bf$cf$e3$d3$cd$0d$0a>~tmp.txt
chcp 936 >nul
type ~tmp.txt
pause
I personally could not get it to work but allegedly this code builds a program called echoo.com which strips CRLF's from txt files in DOS from within a batch file like SET CWD= or 1st temp file.

Many say it is a dangerous program to play with & for the ignorant like me that certainly would apply. Debug is presant in all OS's up to Win7 (That is windows Os's) Scary, dangerous or not I think it is very relevant & very useful. Would it be safer to run test scripts within a sandbox or would "W" overide the sandbox? Anyway less of the rant & onward. I get excited & carried away sometimes. Anyway your efforts and explanation are very much appreciated "Thankyou" Penpen.

@jfl - Found this script on my travels @
https://pement.org/sed/bat_env.htm
Solution (c): Use DEBUG to create a temporary file.
The following solution requires no user intervention, nor does it require single linefeeds in a DOS batch file. DEBUG.EXE is included in all standard distributions of MS-DOS and is in Windows 95/98 in C:\WINDOWS\COMMAND, so you can use it unless someone has deleted it.

Code: Select all

@echo off
:: assume that the datafile exists already in ANSWER.DAT [Could be pre-made in batch]
echo e 100 "set myvar=" > TEMP.FIL
echo n PREFIX.DAT >> TEMP.FIL
for %%i in (rcx a w q) do echo %%i >> TEMP.FIL
debug < TEMP.FIL
copy PREFIX.DAT+ANSWER.DAT VARIAB.BAT
call VARIAB.BAT
echo Success! The value of myvar is: [%myvar%].
:: erase temp files ...
for %%f in (PREFIX.DAT ANSWER.DAT VARIAB.BAT TEMP.FIL) do del %%f >NUL
Many people are skittish about using DEBUG and rightfully so, since DEBUG can crash a hard drive or delete files and directories. Therefore, here is an explanation of what the previous commands actually do. I obtained these commands from Dan Gookin's Guide to Underground DOS 6.0 (Bantam Books, 1993), pp. 187-190, which tells quite a lot about using DEBUG. For the cautious user, here's what these commands mean to DEBUG:

e 100 "set myvar=" ; at base address 100, Enter this "string"
n PREFIX.DAT ; "n" means set a filename called PREFIX.DAT
rcx ; in Register CX, set the size of the file
a ; filesize A hex (10 bytes) put in register CX
w ; Write the file set by "n", i.e., PREFIX.DAT
q ; Quit DEBUG

Maybe some aspect of the above code could be useful in refinning ideas possibly? The truename presumeably is your file yes, not the inbuilt Windows98SE internal command? Under what circumstances are you able to use your "Truename" program e.g. what OS's is it able to run under & it's any short-comings or limitations & is there a readme help file for syntax flags etc? Your above script also uses Find I see, nothing wrong in that just an observation? Could truename be converted into ascii code like echoo.com above and be embedded within a batch file to run on the fly so to speak?

Someone can correct me if I am wrong in the following statement or amend to suit but is what we are discussing to do with a thing in Unix Bash etc that is referred to as Command-Substitution, BackTicks or sometimes referred to as Backquotes with the ` symbol being used ina generic sense. I believe SED, Unix2dos, AWK, Tr are windows ports that permit this functionality??? I believe in XP cmd a workaround to achieve the same thing uses the SET /P command.

Here's another varient piece of batch code that might prove useful also:

Code: Select all

 ::Into environment variable

: The following is based on a solution by William Allen so, it was NOT
: a competition about, Who can write this more brief than another. The
: @ECHO OFF was actually working. (Tested on Win98).
:
  @echo off> %temp%.\~.bat
  for %%e in ( e5'SET'20'X'3D rcx 6 w5 q ) do echo %%e>> %temp%.\~.bat
  type %temp%.\~.bat |debug %temp%.\~.bat> nul
  echo Hello World>> %temp%.\~.bat
: FIND "ot" <   %0>> %temp%.\~.bat
This batch file outputs the "Hello World" text then if I'm not mistaken injects that into a %var%, maybe of some use possibly?

Another thought was from Stdout to embed that within a Var then from the CD> or %0 thingy temp file convert to Var
as very often there seems to be two temporary files setup e.g. SET CWD= with CRLF's removed (to put both statements on one line) and a further temp file with whatever path CD> or %0 redirects then both are combined into SET CD=[& Whatever path] are then setup into a bat file then call command is issued and the Var is SET. However if the Stdout was converted to Var along with [& whatever path] were set to Var both resultant Vars could be Concat like SET CWD="%CD%%[& Whatever path]%" or SET VAR="%VAR1%%VAR2%" I don't know if this would get round the CRLFs in variable format.

And finally I have discoved a Dos Written MASM Assembly program that strips CRLF's but is only 16Bit, however the OP managed to get the majority of the ASM code translated into 32Bit MASM but left out some of the code as a learning exercise for the OP to practice on. So my point is someone with the knowledge to translate 16bit asm code into 32bit MASM & be able to compile the program could have both 16bit & 32bit varients of the same CRLF stripping program. The programs would be an overhead yes & not written in batch but could prove useful. I will not post the MASM Scripts as they are fairly long but will do if someone with the relevant skill set requires me too perhaps in another section of Dostips?

Best Regards David

ispy
Posts: 16
Joined: 25 Dec 2020 15:36

Re: Equivalent 9XDos code to NT Find bat/cmd path %~dp0

#13 Post by ispy » 08 Jan 2021 03:13

Sorry in addition I forgot to also mention as a P.S.

I found this Web page link entitled - "DOS Remove Linefeed And Carriage Return ?" if you scroll to the second post by a person that goes by the handle of MechaniX2Go. He or she (to be PC correct) also uses debug in a batch format to remove CRLFs again I have tried it but with no success but it might be something I am doing wrong anyway the link is:

https://www.computing.net/answers/progr ... 22821.html

Best Regards :D
ispy

Post Reply