Link to home
Start Free TrialLog in
Avatar of atxman
atxman

asked on

DOS string replace and remove character at end

I have a batch script that accepts as the argument a  directory. I need to first check to see if the last character of the string ends with \ and remove it, if it does. I also need to replace all \ with /. I attempted a solution for this second part but it paritally works. It will remove the data before the : and replace all \ with / but I do not need the data prior to the : removed.

Below is my batch script:

@echo off
IF %1=="" GOTO DEFAULTDIR;
SET dir=%1%
GOTO MAINPROCESS;

:DEFAULTDIR
SET dir=%~p0
#replacing \ with /
set dir=%dir:\=/%
ECHO Using %dir% as parent path

:MAINPROCESS

set jardir=%dir%jars
echo Jar directory is %jardir%
echo Completed

:DONE
ECHO DONE

Open in new window

Avatar of NVIT
NVIT
Flag of United States of America image

>  It will remove the data before the : and replace all \ with / but I do not need the data prior to the : removed.

How about separating it? Instead of
SET dir=%~p0
set dir=%dir:\=/%


Do...
SET dir_tmp=%~p0
set dir=%dir_tmp:\=/%
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of atxman
atxman

ASKER

thanks for the response