Make a Variable of partial text form txt line

November 26, 2010 at 13:29:06
Specs: Windows Vista Home Premium, CPU=intel-core2duo_2.1GHz/RAM=3GB
Hallow every one............

I have a problem with making a variable in Batch(.bat) file...........

I have a text file named "path.txt" (without dabble quotes) and for example it contains the following.....

Running Prosses PID
C:\Windows\system32\csrss.exe 596
C:\Windows\system32\wininit.exe 636
C:\Windows\system32\services.exe 680
C:\Windows\system32\lsass.exe 692
C:\Windows\system32\lsm.exe 700
C:\Windows\system32\winlogon.exe 804
C:\Windows\system32\svchost.exe 896
C:\Windows\System32\igfxtray.exe 3780
C:\Windows\System32\hkcmd.exe 3992
C:\Windows\System32\igfxpers.exe 4020
C:\Windows\System32\NOTEPAD.EXE 4584
C:\Windows\System32\cmd.exe 5696

and i want to make a variable of right side string of a line from the given path.txt content example..............

Example of "right side string" from the path.txt content example given above:-

"C:\Windows\System32\NOTEPAD.EXE" (without dabble quotes)
or "C:\Windows\System32\cmd.exe" (without dabble quotes)


but, the variable should not carry the complete line..............
e.g. "C:\Windows\System32\NOTEPAD.EXE 4584 "
(without dabble quotes)
or, only "C:\Windows\System32\" (without dabble quotes)

Currently i am using the following Syntax :-

@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
cls
:reload
cd "!temp!"
set "FIND=%windir%\system32\find.exe"
set "wmic=%windir%\System32\Wbem\wmic.exe"
!wmic! process get ProcessID,ExecutablePath >"path.txt"
type "path.txt"
for /f "tokens=*" %%a in (path.txt) do (
set /a num+=1
set "list=%%a"
echo.!list!
)
echo:
set /p PID="Type a PID: "
for /f "tokens=1,2 delims= " %%a in ('type "path.txt" ^| !FIND! " !PID! "') do (
set "exepath=%%~dpa"
)
if not defined PID (
echo:No Task Running with/ this PID. & echo: & echo:Press any key to goto reload...
PAUSE>NUL && goto :reload
) else cls && echo: & echo: & echo:%exepath% & echo: &echo:press any key to goto reload...
set "PID="
pause>nul
goto :reload


and, it's resulting output is:- "c:\windows\system32\" (without dabble quotes) if 4584 is given for the "Type a PID: " (without dabble quotes) prompt........

but, i want "C:\Windows\System32\NOTEPAD.EXE" (without dabble quotes) as resulting output if 4584 is given for the "Type a PID: " (without dabble quotes) prompt........ for the path.txt Content witch I have written above................

can any one Help me..............

Please Help me...............


See More: Make a Variable of partial text form txt line

Report •


#1
November 26, 2010 at 19:18:29
@echo off > newfile & setLocal enableDELAYedeXpansion

set /p P=PID?

for /f "tokens=* delims= " %%a in ('find "!P!" ^< PIDlist') do (
set S=%%a
)

for /f "tokens=1 delims=." %%i in ("!S!") do (
echo.%%i.exe
) >> newfile


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
November 27, 2010 at 07:53:10
Thank u M2...........
it works for me with little-bit changes.............

thank u vary mutch again for ur rply M2..............


Report •

Related Solutions


Ask Question