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.s the path we pass.
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
import os
import sys
def search(path):
base = sys.platform
sep = "\\"
if base == "darwin" or "linux":
sep = "/"
if os.path.isdir(path):
try:
for i in os.listdir(path):
if os.path.isdir(path + sep + i):
search(path + sep + i)
else:
print("\n", path + sep + i)
except PermissionError:
print("\n""Отказано в доступе - " + path)
else:
if os.path.isfile(path):
print(path)
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.1.0.tar.gz
(2.4 kB
view hashes)
Built Distribution
Close
Hashes for SearchFile-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc893dca67bdaba7440c101067230f028eb08e725c1c07195d05aa481eba8021 |
|
MD5 | 30c794cafbe5dd1acd11cc41d7347e14 |
|
BLAKE2b-256 | 1ba45f98982cc25756a44613b622d4b62c3c19bb388a5844e31bf0c97b36cd3b |