stabud
03.05.2023, 07:51 |
get filename without extension in BAT (Users) |
Hi All!
When specified on the command line: test.bat C:\test.txt
echo %1 ->>> ok!! Filename
echo "%~n1" ->>> does not work in freedos
How to get file C:\test from file C:\test.txt ??? |
glennmcc
North Jackson, Ohio (USA), 04.05.2023, 02:47
@ stabud
|
get filename without extension in BAT |
> Hi All!
>
> When specified on the command line: test.bat C:\test.txt
>
> echo %1 ->>> ok!! Filename
> echo "%~n1" ->>> does not work in freedos
>
> How to get file C:\test from file C:\test.txt ???
Please elaborate on exactly what you are trying to do
and what the _expected_ result should be.
In which OS _does_ it work correctly ? --- --
http://glennmcc.org/ |
jadoxa
Queensland, Australia, 04.05.2023, 03:08
@ stabud
|
get filename without extension in BAT |
> echo "%~n1" ->>> does not work in freedos
That is NT's CMD.EXE, not DOS' COMMAND.COM. Maybe HXDOS would work?
> How to get file C:\test from file C:\test.txt ???
Since FreeDOS comes with sed (at least, my install did):
echo %1 | sed -r s/^(.*)\..*/\1/ | set /p filename= |
stabud
04.05.2023, 04:35
@ glennmcc
|
get filename without extension in BAT |
> In which OS _does_ it work correctly ?
freedos (default)
> Please elaborate on exactly what you are trying to do
> and what the _expected_ result should be.
It is necessary to send a text file to the BAT parameter of the file and get its name without the extension , because the EXE file will be compiled from this text file. The name of this EXE is required to run. On other systems, this is not a problem, but on DOS the COMMAND.com interpreter is very simple and it does not seem to be able to get part of a filename in a simple way.
> That is NT's CMD.EXE, not DOS' COMMAND.COM.
I have already understood that DOS COMMAND.COM cannot do this without third-party tools. For some reason, some sites wrote that it works in DOS...
I found an alternative way: pass one more parameter to the BAT file, where I will specify the exact name.
Thanks everyone for the replies! |
glennmcc
North Jackson, Ohio (USA), 04.05.2023, 17:09
@ stabud
|
get filename without extension in BAT |
> > In which OS _does_ it work correctly ?
>
> freedos (default)
>
> > Please elaborate on exactly what you are trying to do
> > and what the _expected_ result should be.
>
> It is necessary to send a text file to the BAT parameter of the file and
> get its name without the extension , because the EXE file will be compiled
> from this text file. The name of this EXE is required to run. On other
> systems, this is not a problem, but on DOS the COMMAND.com interpreter is
> very simple and it does not seem to be able to get part of a filename in a
> simple way.
>
> > That is NT's CMD.EXE, not DOS' COMMAND.COM.
>
> I have already understood that DOS COMMAND.COM cannot do this without
> third-party tools. For some reason, some sites wrote that it works in
> DOS...
Yeah...
I have noticed that many WinAddicts refer to the NTVDM
as being DOS, but it is of-course _NOT_ DOS.
> I found an alternative way: pass one more parameter to the BAT file, where
> I will specify the exact name.
>
> Thanks everyone for the replies!
Well, at-least you found a workaround to get what you need in _real_ DOS. --- --
http://glennmcc.org/ |
ecm
Düsseldorf, Germany, 04.05.2023, 17:57
@ glennmcc
|
get filename without extension in BAT |
> > > That is NT's CMD.EXE, not DOS' COMMAND.COM.
> >
> > I have already understood that DOS COMMAND.COM cannot do this without
> > third-party tools. For some reason, some sites wrote that it works in
> > DOS...
>
> Yeah...
> I have noticed that many WinAddicts refer to the NTVDM
> as being DOS, but it is of-course _NOT_ DOS.
NTVDM is a virtual machine running a DOS, which happens to be specific to NTVDM and not fully compatible to other DOSes. However, cmd.exe is an MSWindows program shell - it isn't NTVDM. (And NTVDM was only bundled with 32-bit MSW NT releases, whereas cmd.exe runs on all MSW NT.) --- l |
RayeR
CZ, 06.06.2023, 13:59
@ stabud
|
get filename without extension in BAT |
> Hi All!
>
> When specified on the command line: test.bat C:\test.txt
>
> echo %1 ->>> ok!! Filename
> echo "%~n1" ->>> does not work in freedos
>
> How to get file C:\test from file C:\test.txt ???
Why not use instead a name without extension as input parameter and then work with %1.txt and %1.exe in batch file? I know it's not ideal when you use commandline auto completition utility that will automatically fill the whole name with extension. Or as suggested include sed from freedos or djgpp to your toolchain. --- DOS gives me freedom to unlimited HW access. |