@echo off & setlocal enableextensions
echo %path%;^
|gawk -F; "{for (i=1;i<=NF-1;++i) printf \"%%s\n\",$i}"
endlocal & goto :EOF
The output might be e.g.
C:\_D\TEST>cmdfaq
c:\_f\xtools
c:\_f\tools
c:\_f\ftools
c:\_e\arczip
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\Program Files\PC-Doctor for Windows\services
C:\Program Files\TSEpro
C:\Program Files\010Editor
Or with straight script
@echo off & setlocal enableextensions
for /f "tokens=1-15 delims=;" %%a in ("%path%") do (
if not [%%a]==[] echo %%a
if not [%%b]==[] echo %%b
if not [%%c]==[] echo %%c
if not [%%d]==[] echo %%d
if not [%%e]==[] echo %%e
if not [%%f]==[] echo %%f
if not [%%g]==[] echo %%g
if not [%%h]==[] echo %%h
if not [%%i]==[] echo %%i
if not [%%j]==[] echo %%j
if not [%%k]==[] echo %%k
if not [%%l]==[] echo %%l
if not [%%m]==[] echo %%m
if not [%%n]==[] echo %%n
if not [%%o]==[] echo %%o
)
endlocal & goto :EOF
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful script files and tricks ftp://garbo.uwasa.fi/pc/link/tscmd.zip
Nice, and although it is not to the same purpose I would mention
the Bill Stewert editpath.exe utility as on topic in terms of
results for those that may be interested.
editpath -l -s -x
for example.
http://internet.cybermesa.com/~bstewart/misctools.html
http://internet.cybermesa.com/~bstewart/files/epath1.zip
Lines that don't begin with two spaces have wrapped accidentally
====Begin cut-and-paste (omit this line)
@ECHO OFF
SETLOCAL
SET P=%PATH%
:LOOP
FOR /f "tokens=1* delims=;" %%A IN ("%P%") DO (
ECHO/%%A
SET P=%%B
IF DEFINED P GOTO LOOP
)
====End cut-and-paste (omit this line)
Simulated Win2000 for study/demo use. Cut-and-paste as Batch text file.
Batch file troubleshooting: http://www.allenware.com/find?UsualSuspects
--
William Allen
Free interactive Batch Course http://www.allenware.com/icsw/icswidx.htm
Batch Reference with examples http://www.allenware.com/icsw/icswref.htm
From email address not checked. Contact us at http://www.allenware.com/
>DRAFT:
>115) How can I decompose the path to be one folder per line?
@echo off
for %%a in ("%path:;=" "%") do echo %%~a
or even:
@for %%a in ("%path:;=" "%") do @echo %%~a
Thanks,
Clay Calvert
CCal...@Wanguru.com
Replace "W" with "L"
> ====Begin cut-and-paste (omit this line)
> @ECHO OFF
(snip)
Excellent! Tested with success and a Google repository pointer to
your posting added to this FAQ item.
> for %%a in ("%path:;=" "%") do echo %%~a
Now that is truly inventive! Tested with success and a Google
repository pointer to your posting added to this FAQ item.
All the best, Timo
Let expand on your inventive tip. It gives the key to e.g. listing
all the *.BAT files which apprear at the path:
@echo off & setlocal enableextensions
for %%a in ("%path:;=" "%") do (
for /f %%f in ('dir /b /a:-d /o:n %%~a\*.bat') do (
echo %%~a\%%f)
)>>%temp%\temp.dir
for %%c in (type del) do call %%c %temp%\temp.dir
>> for %%a in ("%path:;=" "%") do echo %%~a
>
>Now that is truly inventive! Tested with success and a Google
>repository pointer to your posting added to this FAQ item.
Thank you very much. 'Tis an honor.
Peace,
Clay
>Let expand on your inventive tip. It gives the key to e.g. listing
>all the *.BAT files which apprear at the path:
How about?
@echo off
for %%a in ("%path:;=" "%") do (
for %%g in ("%%~a\*.bat") do echo %%~fg)
Note the "%%~a\*.bat" should be quoted.
Thanks again,
> for %%a in ("%path:;=" "%") do (
> for %%g in ("%%~a\*.bat") do echo %%~fg)
That is clarly better than what I posted since it avoids the "File
not found" problem on folders that contain no *.BAT files. Well
done.
I think that this might deserve an item of its own in the FAQ.
>I think that this might deserve an item of its own in the FAQ.
Defnitely an honor.
Since it looks like you may be heading in this direction. Here is a
"which" routine I originally wrote 4 years ago, but it mandated no
extension in the argument. This is a re-write in which (pun intended)
extensions are optional.
@echo off&echo.
(set WF=)
for %%a in ("" %PATHEXT:;= %) do (
if "%WF%"=="" if exist "%~1%%~a" set WF=%CD%\%~1%%~a)
for %%a in ("" %PATHEXT:;= %) do (
if "%WF%"=="" for %%g in ("%~1%%~a") do (
if exist "%%~$PATH:g" set WF=%%~$PATH:g))
if defined WF (echo %WF%) else echo "%~1" Not Found
Test with strings such as "Notepad" or "win".
Now, if we can just get a routine to enumerate internal commands.
Actually, I've got an idea for that but I have to run "literally" now.
As an aside, it easy to become fond of the "/f" switch in "for". Often
the standard capabilities of that command don't even register as an
option.
Thanks
> Here is a
> "which" routine I originally wrote 4 years ago, but it mandated no
> extension in the argument. This is a re-write in which (pun intended)
> extensions are optional.
Also a nice one. Tested. Definitely worth a Google link my FAQ in
the path item.
Apropos, I have the following solution in my FAQ as item #46, but it
requires the extension.
46) Is a program available in the default folder or at path?
A counterpart of the UNIX "which" command.
@echo off & setlocal enableextensions enabledelayedexpansion
::
if [%1]==[] (
echo Usage: %~0 [Filename]
goto :EOF)
::
if not [%2]==[] (
echo Usage for long file names: %~0 ["Filename"]
goto :EOF)
::
set target_=%~1
::
for %%f in ("%target_%") do set where_="%%~$PATH:f"
if exist "%target_%" set where_="%cd%\%target_%"
if [%where_%]==[""] (
echo "%target_%" not found at path or current folder
) else (
set where_=!where_:"=!
echo where_=!where_!)
::
endlocal & goto :EOF
>Clay Calvert <ccal...@Wanguru.com> wrote:
>> Since it looks like you may be heading in this direction. Here is a
>> "which" routine I originally wrote 4 years ago, but it mandated no
>> extension in the argument. This is a re-write in which (pun intended)
>> extensions are optional.
>
>Apropos, I have the following solution in my FAQ as item #46, but it
>requires the extension.
>
>46) Is a program available in the default folder or at path?
>
>A counterpart of the UNIX "which" command.
> @echo off & setlocal enableextensions enabledelayedexpansion
So far, this "which" seems to work without, and with, extensions, and
is fairly accurate at identifying internal commands. Hopefully, it
will work with localized operating systems, and it can probably be
easily modified to work with a 64-bit OS.
@echo off&echo.
(set WF=)
for %%a in ("" %PATHEXT:;= %) do (
if "%WF%"=="" if exist "%~1%%~a" set WF=%CD%\%~1%%~a)
for %%a in ("" %PATHEXT:;= %) do (
if "%WF%"=="" for %%g in ("%~1%%~a") do (
if exist "%%~$PATH:g" set WF=%%~$PATH:g))
if NOT "%~x1"=="" goto:END
for /f "delims=." %%a in ('help.exe *') do set HlpErr=%%a
help.exe "%~1" |find "%HlpErr%">nul && goto:END
for %%a in (exe com) do (
if /i "%WF%"=="%windir%\system32\%~1.%%a" goto:END)
set WF="%1" is an internal command
:END
if defined WF (echo %WF%) else (
echo The file: "%~1" was not found)
Thanks,
> So far, this "which" seems to work without, and with, extensions, and
> is fairly accurate at identifying internal commands. Hopefully, it
(snip the code)
Clay, is this effectively the same code you posted earlier, or is it
a new version needing an updated pointer in my FAQ? The one I
included in the said item is
References/Comments:
http://www.google.com/groups?selm=nbh5i1tglbr6o3vml...@4ax.com
>> So far, this "which" seems to work without, and with, extensions, and
>> is fairly accurate at identifying internal commands. Hopefully, it
>
>(snip the code)
>
>Clay, is this effectively the same code you posted earlier, or is it
>a new version needing an updated pointer in my FAQ? The one I
>included in the said item is
It is a newer version. This version should properly identify internal
commands, such as CD, DIR, BREAK and VERIFY.
>>Clay, is this effectively the same code you posted earlier, or is it
>>a new version needing an updated pointer in my FAQ? The one I
>>included in the said item is
>
>It is a newer version. This version should properly identify internal
>commands, such as CD, DIR, BREAK and VERIFY.
Even newer version, with a serious bug removed.
@echo off&echo.
(set WF=)
for %%a in ("" %PATHEXT:;= %) do (
if not defined WF if exist "%~1%%~a" set WF=%CD%\%~1%%~a)
for %%a in ("" %PATHEXT:;= %) do (
if not defined WF for %%g in ("%~1%%~a") do (
if exist "%%~$PATH:g" set WF=%%~$PATH:g))
if NOT "%~x1"=="" goto:END
for /f "delims=." %%a in ('help.exe *') do set HlpErr=%%a
help.exe "%~1" |find "%HlpErr%">nul && goto:END
for %%a in (exe com) do (
if /i "%WF%"=="%windir%\system32\%~1.%%a" goto:END)
set WF="%~1" is an internal command
:END
if defined WF (echo. { %WF% }) else (
echo The file: "%~1" was not found)
Thanks and Sorry Timo,
Clay
Ok, the Message-Id captured.