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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
shlexwhichplus-0.10.tar.gz
(4.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shlexwhichplus-0.10.tar.gz.
File metadata
- Download URL: shlexwhichplus-0.10.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/4.0.2 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
120857831d259665abcdda8740e2ff504eb824c4781bd70ab422f63ec202da8e
|
|
| MD5 |
0d41885f368993d34f4ad8bca8db2163
|
|
| BLAKE2b-256 |
420123d5a8f70b56580e31b2a90e16cf9cddab91c0cd244080dc5a3fca53245e
|
File details
Details for the file shlexwhichplus-0.10-py3-none-any.whl.
File metadata
- Download URL: shlexwhichplus-0.10-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/4.0.2 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e08408bce56653eb2ac6524c6dc2f7a53c049343534bfe5d901c49cf74fc197
|
|
| MD5 |
e7519c3a9518e5a268fd721763d6ff27
|
|
| BLAKE2b-256 |
12515051ca22ef58c44b1032d7405c5b98730eaf80d672ed47cbf249a28898de
|