MSX-DOS2 batch file: get filename without extension from parameter

Por The Apeman

Resident (55)

Imagen del The Apeman

08-03-2020, 19:26

Hi all,

When I get a filename such as "README.TXT" in my batch file as %1, is there a way to get only the "README"-part from it, without the DOS filename extension?

Also, where can I find good user documentation on this?

Any help greatly appreciated!

Login sesión o register para postear comentarios

Por gdx

Prophet (3683)

Imagen del gdx

09-03-2020, 10:32

I made the following batch file named TST.BAT and create a text file named FILE.TXT.

echo %0
echo %1

When I enter TST FILE.TXT, I get:

TST
FILE.TXT

If I enter TST.BAT FILE.TXT, I get:

TST.BAT
FILE.TXT

It works fine for me. File extensions are present. %0 is the command, %1 is the first parameter. We can use 9 parameters (%1 ~ %9).

Tested with:
MSX-DOS kernel version 2.20 (from the Sunrise CF)
MSXDOS2.COM version 2.30
COMMAND2.COM version 2.44

What DOS version have you?

Por sdsnatcher73

Paragon (1095)

Imagen del sdsnatcher73

09-03-2020, 10:55

He wants to split of the filename from the extension from the first argument %1.

Por gdx

Prophet (3683)

Imagen del gdx

09-03-2020, 11:06

Sorry, I misread.

Por The Apeman

Resident (55)

Imagen del The Apeman

09-03-2020, 19:48

No apology needed, thanks for your reply.

I use Nextor 2.1.0 with COMMAND2.COM 2.44, which I hope will, as far as this context is concerned, be the same as MSX-DOS2. Or is it not?

Anyway, I would love to find some kind of handbook or other documentation (in English) about this. Does anyone know where I can find that?

Por sdsnatcher73

Paragon (1095)

Imagen del sdsnatcher73

09-03-2020, 21:09

Here is the Manual for MSX-DOS 2.20. I don’t believe COMMAND2.COM (aka the Command Interpreter or Shell) can split a filename into it’s basename and extension. Also there is no stream editor like sed on Linux as far as I know of. But it should not be to create a program that takes a filename and outputs the basename or the extension (although I could not do it myself for MSX), e.g.

A:\> FILE.COM /B README.TXT
README

A:\> FILE.COM /E README.TXT
TXT

but then I don’t know if we could put the output of a command into an environment variable (like modern shells are able to), which I guess would be necessary to make it useful in a batch file.

Por Dolphin101546015

Champion (273)

Imagen del Dolphin101546015

09-03-2020, 21:45

The Apeman wrote:

Hi all,

When I get a filename such as "README.TXT" in my batch file as %1, is there a way to get only the "README"-part from it, without the DOS filename extension?

Also, where can I find good user documentation on this?

Any help greatly appreciated!

s.bat:

echo File name: %@name[%1]%
echo File extention: %@ext[%1]%
A:\>s render.com
File name: RENDER
File extention: COM

Also, like MSX Basic, MSX-DOS2 have %@MID[]% and %@LEN[]% (and left & right too)

Por The Apeman

Resident (55)

Imagen del The Apeman

09-03-2020, 21:50

Dolphin101546015 wrote:

s.bat:

echo File name: %@name[%1]%
echo File extention: %@ext[%1]%

Also, like MSX Basic, MSX-DOS2 have %@MID[]% and %@LEN[]% (and left & right too)

Fantastic. That's exactly what I needed. Big smile Thanks!

Por Dolphin101546015

Champion (273)

Imagen del Dolphin101546015

09-03-2020, 23:44

gdx wrote:

It works fine for me. File extensions are present. %0 is the command, %1 is the first parameter. We can use 9 parameters (%1 ~ %9).

Tested with:
MSX-DOS kernel version 2.20 (from the Sunrise CF)
MSXDOS2.COM version 2.30
COMMAND2.COM version 2.44

The number of parameters for batch files has been increased. Now a maximum of 255 parameters can be passed using %n, instead of only 9.

Por sdsnatcher73

Paragon (1095)

Imagen del sdsnatcher73

10-03-2020, 13:43

Dolphin101546015 wrote:
The Apeman wrote:

Hi all,

When I get a filename such as "README.TXT" in my batch file as %1, is there a way to get only the "README"-part from it, without the DOS filename extension?

Also, where can I find good user documentation on this?

Any help greatly appreciated!

s.bat:

echo File name: %@name[%1]%
echo File extention: %@ext[%1]%
A:\>s render.com
File name: RENDER
File extention: COM

Also, like MSX Basic, MSX-DOS2 have %@MID[]% and %@LEN[]% (and left & right too)

Very nice indeed. Was this documented somewhere or was it discovered through reverse engineering?

Por Dolphin101546015

Champion (273)

Imagen del Dolphin101546015

10-03-2020, 13:50