Create 2 variables from 1 tring

April 3, 2010 at 07:31:00
Specs: Windows XP

Im trying to split a string to 2 (%path% and %file%)

for example:
set pathtofile=C:\Program Files\MyFolder\bin\file.exe

and then some how separate the file from the path and set a variable for the path and another for the file

(in php I would simply create an array from the string separating the values by \, and then just loop the array to create 2 variables)

I asked in another forum and the guy just posted this code but didnt explained himself, and plus its not what Im looking for, this only gives me access to the path.

REM @Echo Off
Set Var=C:\My test\helloworld\bigmike\england\london\test.bat

For %%i in ("%Var%") Do Set CF=%%~dpi
Set CF=%CF:~0,-1%
REM If "%CF:~-1,1%"=="\" GoTo :DONE
Set CF=%CF:~0,800%
echo %CF%

can somebody tell me how to do what Im looking for, and please explain yourself, I want to learn ;)

See More: Create 2 variables from 1 tring

Report •

April 3, 2010 at 08:19:50
@echo off & setLocal EnableDELAYedeXpansion

set P=C:\Program Files\MyFolder\bin\file.exe

for /f "tokens=* delims= " %%a in ("!P!") do (
set v1=%%~DPa
set v2=%%~NXa

Helping others achieve escape felicity


Report •

April 3, 2010 at 12:26:32
ha ha! yeah, look about 6 posts down, same basic question last night:

Report •

Related Solutions

Ask Question