Search for files by the specified path.
Project description
SearchFile
Table of contents
Installation
Installation using a terminal:
pip install SearchFile
Description
This library is designed to search for files by a given path.
Using
import SearchFile
or
from SearchFile import search
The argument of the search
function is the path passed as a string.
For Windows
Also, the directory separator should be written in the form \\
, so as not to form control characters (\n, \t, \r, etc.). Examples:
search("C:\\Users")
search("D:\\Downloads\\test.txt")
search("D:\\Git\\cmd")
Linux
The directory separator should be used /
. Examples:
search("/home/artem/desktop/")
search("/home/artem/tmp/file1")
search("/home/artem/desktop/tmp/")
Mac OS
The directory separator should be used /
. Examples:
search("/Library/Desktop Pictures")
search("/Library/Desktop Pictures/pictures1.jpg")
search("/Library/Desktop Pictures/gallery")
Code
from os import path, listdir
def search(tpath):
if path.isdir(tpath):
try:
for dirs in listdir(tpath):
if path.isdir(path.join(tpath, dirs)):
search(path.join(tpath, dirs))
else:
print("\n", path.basename(path.join(tpath, dirs)))
except PermissionError:
print("\n""Отказано в доступе - " + tpath)
else:
if path.isfile(tpath):
print(path.basename(tpath))
else:
print("Неверно указан путь!")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
SearchFile-0.2.0.tar.gz
(2.3 kB
view hashes)
Built Distribution
Close
Hashes for SearchFile-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c82c36e51ee3d97a2764258f0127aba63d12c1ced9eaec608a1a82277dfad010 |
|
MD5 | bfb79e6ca151a1bdaabe00a036432932 |
|
BLAKE2b-256 | 8c68ef51ba5f235b0b993ff3e848f92258cb7b25993cfd85efeb428c95d1362b |