1.

Solve : How to split any line(path) throught command line (for batch file)??

Answer»

Quote from: Sidewinder on September 12, 2008, 08:16:46 AM

Code: [Select]if .%%G==. goto getout

That's a new one on me. I am used to doing it this way

Code: [Select]if "%%G"=="" goto getout
hi side winder
i used the code send by you and after that code i have to set some enviorment
but after that it doesnot set any enviorment varible, can u tell me why this happens?

i think because of setlocal enabledelayedexpansionQuote
i think because of setlocal enabledelayedexpansion

Indeed it is. Usually I try not to use setlocal for this very reason. The call instruction can be put to good use in this context.

Code: [Select]@echo off
for /F "tokens=* delims=\" %%a in ('cd') do (
set parse=%%a
call set new=%%parse:\= %%
)

for %%G in (%new%) do (
if .%%G==. goto getout
if %%G==test goto getout
call set p=%%p%%\%%G
)
:getout
set p=%p:~1%
echo %p%

After the batch file executes, the variable p will CONTAIN the directory name.

Good luck. i used following code

setlocal enabledelayedexpansion
set DIR=
for /f "tokens=* delims=\" %%P in ('cd') do (
set mypath=%%P
set array=!mypath:\= !
)

for %%E in (%array%) do (
if .%%E==. goto getout
if %%E==test goto getout
call set DIR=%%DIR%%\%%E
)
:getout

set TOP_DIR=%DIR%//test1

and if i removed setlocal enabledelayedexpansion
and prints valuse of TOP_DIR = \!mypath:\\!\\test1

and if print the value of TOP_DIR with enabledelayedexpansion
it is TOP_DIR = %TOP_DIR%
that is no value is set

so now what should doneIf you remove the setlocal statement, you must also remove any references to delayed expansion:

Code: [Select]set DIR=
for /f "tokens=* delims=\" %%P in ('cd') do (
set mypath=%%P
call set array=%%mypath:\= %%
)

for %%E in (%array%) do (
if .%%E==. goto getout
if %%E==test goto getout
call set DIR=%%DIR%%\%%E
)
:getout

set TOP_DIR=%DIR%//test1

Why are you using both FORWARD and BACKWARD slashes? They are not interchangeable.

Why keep changing the variable (both declared and generated) names? Many people read these posts; let's try and keep it simple.

I thought you were trying to find the parents of the test directory on the path. Now I see you're appending test1 to the generated path. Any more surprises first of all sorry for changing variables .


now let me explain you what i was doing
i find out the the parents of the test directory, which i FOUND with the hlep of ur code.
After then i want to set some eviorment variables using this DIR(perent directory ) path.
and that variables value should be fixed till that command prompt is open or setup is runs again.

so finally The thing is done .
No more surprisess.
and thanks for that much support.


Discussion

No Comment Found