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):
list_file = []
if path.isdir(tpath):
try:
for dirs in listdir(tpath):
if path.isdir(path.join(tpath, dirs)):
search(path.join(tpath, dirs))
else:
list_file.append(path.basename(path.join(tpath, dirs)))
print("\n", path.basename(path.join(tpath, dirs)))
except PermissionError:
list_file.append(tpath)
print("\n""Отказано в доступе - " + tpath)
else:
if path.isfile(tpath):
list_file.append(path.basename(tpath))
print(path.basename(tpath))
else:
print("Неверно указан путь!")
return list_file
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.3.1.tar.gz
(2.4 kB
view hashes)
Built Distribution
Close
Hashes for SearchFile-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa8d4f687388539148b7a00b905902cda6ae94d275d47cf5cc327c5db200cac8 |
|
MD5 | 02727a89bc999539dcdff029cf5111b8 |
|
BLAKE2b-256 | 25321a47ddd7d90d822c1d75979ca4466f985bcb65da10ffa3fb0c6d7186c56b |