0

I have path in a variable from registry that looks like this :

SET dirpath="D:\Veritas\product\7.5.0.2\bin\DBBACKEX.EXE BACKUPDIR"

I need output only upto bin folder using windows batch command that should look this: D:\Veritas\product\7.5.0.2\bin

I used a simple VBScript within the batch command like in below code which did the job, but i need it using batch command only without the use of another file.

FOR /F "usebackq tokens=*" %%p in (`CSCRIPT //nologo regpath.vbs %dirPath%`) DO SET VPath=%%p

I don't see much string manipulation functions in batch commands, I want to remove the CSCRIPT line in above code and use only batch command. Can someone please help.

2 Answers 2

2

To "trim the path upto a certain string" using the string "bin" as you requested, you may use this simple method:

@echo off
setlocal

SET "dirpath=D:\Veritas\product\7.5.0.2\bin\DBBACKEX.EXE BACKUPDIR"

SET "VPath=%dirpath:bin=bin" & rem "%"

echo %VPath%

The trick consist in split the path at the desired string and eliminate the rest via a rem command; you may remove the @echo off line and execute the code in order to see what exactly is executed...

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

1 Comment

Super @Aacini. Works as expected ! Thanks a lot for help.
1

use for modifiers to get the drive/path:

for %%a in ("%dirpath%") do set dirpath=%%~dpa

See for /? for a description of the modifiers.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.