2

I'm trying to write some dos batch script for manipulating some paths. I haven't done this in years so I might be rusty.

The path is relative and given from the command line as argument

@echo off
set wpath=%1
@echo.%wpath%
set newpath=%wpath:~0,-4%
@echo.%newpath%

The thing I'm trying to accomplish is to get rid of the extension

script.bat whatever/test.txt
whatever/test.txt
whatever/test

But I'm getting

script.bat whatever/test.txt
whatever/test.txt
<emptyline>

I'm using dosemu-1.4.0.1/DOSBox-0.74 and this as a reference

3
  • 1
    That's correct - I've just double checked in my CMD and it worked as expected. I can only assume that dosemu isn't emulating the commands correctly! Commented Oct 17, 2011 at 21:02
  • Hm, that's what I was afraid of. Any other ways I can achieve this? Commented Oct 17, 2011 at 21:07
  • All I can think of at the moment is (if you have an idea of what files will be passed), do a string replace for all possible extensions... ie set path=%path:.txt=% .... set path=%path:.pdf=% ... etc - let me know if you find another way, or look for a different emulator! Commented Oct 17, 2011 at 21:24

2 Answers 2

2

You could check the limits of dosemu, can it handle
echo %path:~0,4% (only positives) than you only need to get the string length
or you can try
for %%A in ("%path%") do echo %%~dpnA

Sign up to request clarification or add additional context in comments.

3 Comments

the first one returns <blankline> the second one %dpnA
Do you test the second on the command line (only single percents) or in a batch (double percent required)
C:\>for %A in ("%path%") do echo %~dpnA C:\>echo %~dpnA %~dpnA C:\>
2

Apparently those are wimcmd extensions and not to be found in DOS, if anyone still gets here :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.