On 6/10/2023 12:32 PM, Eryk Sun wrote:
On 6/10/23, Thomas Passin via Python-list <python-list@python.org> wrote:
We can find pip.exe using good old-fashioned dir (we don't need any
new-fangled Powershell):
C:\Users\tom>dir AppData\Local\Programs\Python /Aa /S /W /B |find
"pip"|find "Scripts"
CMD's `dir` and `for` commands support simple wildcard matching. For
example, the following recursively searches for a file named
"pip*.exe" under "%ProgramFiles%\Python311":
C:\>dir /b /s "%ProgramFiles%\Python311\pip*.exe"
C:\Program Files\Python311\Scripts\pip.exe
C:\Program Files\Python311\Scripts\pip3.11.exe
C:\Program Files\Python311\Scripts\pip3.exe
C:\>for /r "%ProgramFiles%\Python311" %f in (pip*.exe) do @(echo %f)
C:\Program Files\Python311\Scripts\pip.exe
C:\Program Files\Python311\Scripts\pip3.11.exe
C:\Program Files\Python311\Scripts\pip3.exe
The following recursively searches for a directory named "pip" under
"%ProgramFiles%\Python311:
C:\>dir /ad /b /s "%ProgramFiles%\Python311\pip"
C:\Program Files\Python311\Lib\site-packages\pip
Or search for a directory name that starts with "pip":
C:\>dir /ad /b /s "%ProgramFiles%\Python311\pip*"
C:\Program Files\Python311\Lib\site-packages\pip
C:\Program Files\Python311\Lib\site-packages\pip-22.3.1.dist-info
C:\Program Files\Python311\Lib\site-packages\win32\Demos\pipes
With a recursive `for /r path [/d]` loop, the strings in the set have
to include wildcard characters to actually check for an existing file
or directory, else each string in the set simply gets appended to the
directory names in the recursive walk. For example, the following
recursively searches for a directory (i.e. /d) named "pip*" under
"%ProgramFiles%\Python311":
C:\>for /r "%ProgramFiles%\Python311" /d %d in (pip*) do @(echo %d)
C:\Program Files\Python311\Lib\site-packages\pip
C:\Program Files\Python311\Lib\site-packages\pip-22.3.1.dist-info
C:\Program Files\Python311\Lib\site-packages\win32\Demos\pipes
To match a specific name, you can filter the matches using an `if`
statement to compare the base filename of the loop variable (i.e.
[n]ame + e[x]tension) with the required name. For example:
C:\>for /r "%ProgramFiles%\Python311" /d %d in (pip*) do @(
More? if "%~nxd"=="pip" echo %d)
C:\Program Files\Python311\Lib\site-packages\pip
Yes; I didn't want to get too esoteric with commands that are hard to
figure out and remember, because then why not use Powershell, whose
commands are hard to figure out and remember?
--
https://mail.python.org/mailman/listinfo/python-list