Skip to main content

Search for files by the specified path.

Project description

SearchFile

Table of contents

  1. Installation
  2. Description
  3. Using
  4. Code

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)

Uploaded Source

Built Distribution

SearchFile-0.3.1-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page