Like shutil.which, but for all file types, and multiple results (if desired)
pip install shlexwhichplus
Tested against Windows 10 / Python 3.10 / Anaconda
import shutil
from shlexwhichplus import which_plus
print('_________________shutil.which')
print(shutil.which('python.exe'))
print(shutil.which('Python.exe'))
print(shutil.which('output.avi'))
print(shutil.which('output.avi')),
print(shutil.which(b'teSt.txt'))
print(shutil.which(b'teSt.txt'))
print('_________________which_plus')
print(which_plus('python.exe', mode='one', path=None))
print(which_plus('Python.exe', mode='all', path=None))
print(which_plus('output.avi', mode='all', path=None))
print(which_plus('output.avi', mode='one', path=None))
print(which_plus('api-ms-win-crt-conio-l1-1-0.dll', mode='one', path=None))
print(which_plus('api-ms-win-crt-conio-l1-1-0.dll', mode='all', path=None))
print(which_plus('Python.exe', mode='BLALBLALA', path=None)) # one if mode not in [all,one]
print(which_plus('TeST.txt', mode='all', path=None))
print(which_plus('teSt.txt', mode='one', path=None))
print(which_plus(b'teSt.txt', mode='all', path=None))
print(which_plus(b'teSt.txt', mode='one', path=None))
# output
_________________shutil.which
C:\ProgramData\anaconda3\envs\dfdir\python.exe
C:\ProgramData\anaconda3\envs\dfdir\Python.exe
None
None
None
None
_________________which_plus
C:\ProgramData\anaconda3\envs\dfdir\python.exe
['C:\\ProgramData\\anaconda3\\envs\\dfdir\\python.exe']
['C:\\cprojekt\\output.avi', 'C:\\ProgramData\\anaconda3\\envs\\dfdir\\output.avi']
C:\ProgramData\anaconda3\envs\dfdir\output.avi
C:\ProgramData\anaconda3\envs\dfdir\api-ms-win-crt-conio-l1-1-0.dll
['C:\\ProgramData\\anaconda3\\envs\\dfdir\\api-ms-win-crt-conio-l1-1-0.dll', 'C:\\Program Files\\Microsoft\\jdk-11.0.16.101-hotspot\\bin\\api-ms-win-crt-conio-l1-1-0.dll', 'C:\\ProgramData\\anaconda3\\envs\\dfdir\\Library\\bin\\api-ms-win-crt-conio-l1-1-0.dll', 'C:\\Program Files\\Eclipse Adoptium\\jdk-11.0.18.10-hotspot\\bin\\api-ms-win-crt-conio-l1-1-0.dll', 'C:\\Program Files\\Amazon Corretto\\jdk17.0.6_10\\bin\\api-ms-win-crt-conio-l1-1-0.dll']
C:\ProgramData\anaconda3\envs\dfdir\python.exe
['C:\\ProgramData\\anaconda3\\envs\\dfdir\\Library\\bin\\TeST.txt', 'C:\\ProgramData\\anaconda3\\envs\\dfdir\\TeST.txt', 'C:\\ProgramData\\anaconda3\\envs\\dfdir\\Scripts\\TeST.txt']
C:\ProgramData\anaconda3\envs\dfdir\TeST.txt
[b'C:\\ProgramData\\anaconda3\\envs\\dfdir\\Library\\bin\\TeST.txt', b'C:\\ProgramData\\anaconda3\\envs\\dfdir\\TeST.txt', b'C:\\ProgramData\\anaconda3\\envs\\dfdir\\Scripts\\TeST.txt']
b'C:\\ProgramData\\anaconda3\\envs\\dfdir\\TeST.txt'
Given a command, mode, and a PATH string, return the path which conforms to the given mode on the PATH,
or None if there is no such file.
:param cmd: A string specifying the command to be searched.
:type cmd: str
:param mode: A string indicating whether to return one or all matches on the PATH.
If 'one', return the first match found on the PATH.
If 'all', return a list of all matches found on the PATH.
If any other string, mode defaults to 'one'.
:type mode: str
:param path: A string representing the search path. If None, uses the current system PATH variable.
:type path: str|None
:return: If mode is 'one', returns the first path found to the given command, or None if not found.
If mode is 'all', returns a list of all paths found to the given command, or an empty list if not found.
:rtype: str or list of str
Metadata
Release files for shlexwhichplus 0.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| shlexwhichplus-0.10.tar.gz | 4.8 kB | Without provenance | Details for shlexwhichplus-0.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| shlexwhichplus-0.10-py3-none-any.whl | Python 3 | none | any | Details for shlexwhichplus-0.10-py3-none-any.whl |
Total release size: 11.0 kB
Release files / shlexwhichplus-0.10.tar.gz
| Download URL | shlexwhichplus-0.10.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
120857831d259665abcdda8740e2ff504eb824c4781bd70ab422f63ec202da8e
|
|
BLAKE2b-256 checksum How to use checksums |
420123d5a8f70b56580e31b2a90e16cf9cddab91c0cd244080dc5a3fca53245e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.10
|
Release files / shlexwhichplus-0.10-py3-none-any.whl
| Download URL | shlexwhichplus-0.10-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2e08408bce56653eb2ac6524c6dc2f7a53c049343534bfe5d901c49cf74fc197
|
|
BLAKE2b-256 checksum How to use checksums |
12515051ca22ef58c44b1032d7405c5b98730eaf80d672ed47cbf249a28898de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.10
|
Security for shlexwhichplus 0.10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.