Skip to main content

FileSystem Pro is designed to identify the operating system (OS) on which it`s running and define the paths to various user directories based on the OS.

Reason this release was yanked:

This version of the project was yanked due to the use of deprecated methods that are no longer supported in the latest version of the platform. We recommend users to upgrade to the latest version of the project which uses the updated methods and ensures better performance and stability.

Project description

FileSystem Pro

FileSystem Pro is designed to identify the operating system (OS) on which it’s running and define the paths to various user directories based on the OS.

Getting Started

Dependencies

It's recommended Python 3.9 or later to use FileSystem Pro. You can download the latest version of Python in python.org.

Installation

Don't forget to upgrade pip:

pip3 install --upgrade pip

And install FileSystem Pro:

pip3 install filesystempro

You can also clone this repo to your local machine using:

git clone https://github.com/hbisneto/FileSystemPro.git

Features

  • Cross-platform Compatibility: The code is designed to work on multiple operating systems, including Linux, Mac, and Windows. This makes it versatile and adaptable to different environments.
  • Directory Path Identification: The code identifies and defines the paths to several common user directories based on the operating system. This includes directories like Desktop, Documents, Downloads, Music, Pictures, Public, Videos, and others.
  • Current Working Directory: The code uses os.getcwd() to get the current working directory.
  • String Formatting: The code uses f-string formatting to create directory paths.
  • Monitoring System: Wrapper acts as a monitoring system for the file system. It keeps track of all activities within the file system.
  • Change Tracking: It records any changes made within the file system. This includes the creation of new files, modification of existing files, and deletion of files.
  • Real-Time Updates: The Wrapper provides real-time updates on any changes made within the file system. This ensures that users have the most current information at all times.
  • Integrity Maintenance: This feature is particularly useful in scenarios where maintaining the integrity and up-to-date status of the file system is crucial. By tracking all changes, the Wrapper helps ensure that the file system remains accurate and reliable.

Wrapper

Wrapper is a comprehensive toolkit that provides a set of utility functions specifically designed to facilitate file and directory operations. These operations may include creating, reading, updating, and deleting files or directories.

Watcher

Wrapper also serves as a monitoring system for the file system. It keeps track of any changes made within the file system, such as the creation of new files, modification of existing files, or deletion of files. This feature allows for real-time updates and can be particularly useful in scenarios where maintaining the integrity and up-to-date status of the file system is crucial.

Usage Example

These directories are dynamically generated based on the operating system platform (linux, darwin for Mac, and Windows)

FileSystem: Default Variables
import filesystem as fs

# prints the current directory
print(fs.CURRENT_LOCATION)

# prints the User directory
print(fs.user)

# prints the Desktop directory
print(fs.desktop)

# prints the Documents directory
print(fs.documents)

# prints the Downloads directory
print(fs.downloads)

# prints the Music directory
print(fs.music)

# prints the Pictures directory
print(fs.pictures)

# prints the Public directory
print(fs.public)

# prints the Videos directory
print(fs.videos)

# prints Templates directory folder in Linux Environments
print(fs.linux_templates) # (specific to Linux)

# prints Applications directory folder in macOS Environments
print(fs.mac_applications) # (specific to Mac)

# prints Movies directory folder in macOS Environments
print(fs.mac_movies) # (specific to Mac)

# prints ApplicationData directory folder in Windows Environments
print(fs.windows_applicationData) # (specific to Windows)

# prints LocalAppData directory folder in Windows Environments
print(fs.windows_localappdata) # (specific to Windows)

# prints Temp directory folder in Windows Environments
print(fs.windows_temp) # (specific to Windows)

# prints Favorites directory folder in Windows Environments
print(fs.windows_favorites) # (specific to Windows)

FileSystem: Reaching Desktop Folder

The following example shows how to get the Desktop directory path

import filesystem as fs

desk = fs.desktop

print(desk)

Output:

## On Linux
/home/YOU/Desktop

## On macOS
/Users/YOU/Desktop

## On Windows
C:\Users\YOU\Desktop

Wrapper: Default Functions
  1. create_directory(path, create_subdirs=True): This function is used to create a directory at the specified path. If create_subdirs is True, the function creates all intermediate-level directories needed to contain the leaf directory. If create_subdirs is False, the function will raise an error if the directory already exists or if any intermediate-level directories in the path do not exist. Default is True
    If the directories already exist, it does nothing.

  2. create_file(file_name, path, text): This function opens a file with the name file_name in the directory specified by path and writes the content of text into the file.

  3. delete(path, recursive=False): This function is designed to delete a directory at a given path.
    If recursive is set to True, the function will delete the directory and all its contents. If it’s False, the function will only delete the directory if it’s empty. Default is False.

  4. enumerate_files(path): This function performs a depth-first traversal of the directory tree at the given path (after expanding any user home directory symbols). It returns a list of dictionaries containing the attributes of each file and directory in the tree.

  5. get_files(path): This function takes a path as input (which can include wildcards), expands any user home directory symbols (~), and returns a list of dictionaries containing the attributes of each file or directory that matches the path.

  6. get_path_properties(pathname): This function takes a file or directory path as input and returns a dictionary containing various attributes of the file or directory. These attributes include the time of last modification, creation time, last access time, name, size, absolute path, parent directory, whether it's a directory or file or link, whether it exists, and its extension (if it's a file).

  7. list_directories(path): This function returns a list of all the directories in a given directory.

  8. list_files(path): This function returns a list of all the files in a given directory.

Wrapper: Watcher

Wrapper Watcher is used to monitor changes in a file system.

  • __init__(self, root): This is the constructor method that initializes the Watcher object with a root directory to watch. It also saves the current state of the file system in self.saved_state.

  • get_state(self, path): This method returns a dictionary where the keys are the absolute paths of all files in the given path and the values are file metadata obtained from the core.enumerate_files(path) function.

  • diff(self): This method compares the current state of the file system with the saved state and identifies any changes (created, updated, or removed files). It returns a list of dictionaries where each dictionary contains the metadata of a changed file and an additional key "change" indicating the type of change.

  • __str__(self): This method returns a string representation of the Watcher object.

This class could be useful in scenarios where you need to monitor changes to a file system, for example, in a backup system or a live syncing service.

Wrapper: Creating a Folder

The following example shows how to create a new directory named database inside the Documents directory using Wrapper

import filesystem as fs
from filesystem import wrapper as wr

bd_folder = "database"
try:
   wr.create_directory(f'{fs.documents}/{bd_folder}')
except:
   print("Could`t create the folder")

Wrapper: Get Files

Get files

The following example shows how to get files information from 'Downloads' folder.

# Let's use 'Downloads' folder as example
# That's why I'll import filesystem
import filesystem as fs
# Let's use Wrapper to get info from files in 'Downloads' folder
from filesystem import wrapper as wr
# Using the get_files syntax
pointers = wr.get_files(f'{fs.downloads}/*')

print(pointers)

Output:

[{'modified': 1695535334.1411633, 'created': 1697604128.7045012, 'access': 1697604129.781534, 'name': 'CLI.py', 'size': 3345, 'abspath': '/Users/YOU/Downloads/CLI.py', 'dirname': '/Users/YOU/Downloads', 'is_dir': False, 'is_file': True, 'is_link': False, 'exists': True, 'ext': 'py'}, {'modified': 1697605101.6574, 'created': 1697683292.4821024, 'access': 1697683294.46923, 'name': 'Python_Logo.png', 'size': 747809, 'abspath': '/Users/YOU/Downloads/Python_Logo.png', 'dirname': '/Users/YOU/Downloads', 'is_dir': False, 'is_file': True, 'is_link': False, 'exists': True, 'ext': 'png'}, {'modified': 1697681746.0940206, 'created': 1697682027.268841, 'access': 1697682292.5433743, 'name': 'Sample_File.py', 'size': 1031, 'abspath': '/Users/YOU/Downloads/Sample_File.py', 'dirname': '/Users/YOU/Downloads', 'is_dir': False, 'is_file': True, 'is_link': False, 'exists': True, 'ext': 'py'}]

Filter files by extension

The following example is using a list comprehension to filter out files with extension .py from the pointers list:

py_files = [x for x in pointers if x["ext"] == "py"]
print(py_files)
[{'modified': 1695535334.1411633, 'created': 1697604128.7045012, 'access': 1697604129.781534, 'name': 'CLI.py', 'size': 3345, 'abspath': '/Users/YOU/Downloads/CLI.py', 'dirname': '/Users/YOU/Downloads', 'is_dir': False, 'is_file': True, 'is_link': False, 'exists': True, 'ext': 'py'}, {'modified': 1697681746.0940206, 'created': 1697682027.268841, 'access': 1697681829.0075543, 'name': 'Sample_File.py', 'size': 1031, 'abspath': '/Users/YOU/Downloads/Sample_File.py', 'dirname': '/Users/YOU/Downloads', 'is_dir': False, 'is_file': True, 'is_link': False, 'exists': True, 'ext': 'py'}]

Get file names inside the filter

The following code is using a list comprehension that prints the names of all filtered files in the py_files list:

print([x["name"] for x in py_files])

Output:

['CLI.py', 'Sample_File.py']

Wrapper: Enumerate files (walk recursively) from a directory

The following code is using a list comprehension to generate a list of all files in the downloads directory:

tree = [x for x in wr.enumerate_files(fs.downloads)]
print(tree)

Output:

[{'modified': 1697683292.4821026, 'created': 1697683292.4821026, 'access': 1697683292.484029, 'name': 'Downloads', 'size': 224, 'abspath': '/Users/YOU/Downloads', 'dirname': '/Users/YOU', 'is_dir': True, 'is_file': False, 'is_link': False, 'exists': True, 'ext': ''}, {'modified': 1697683288.8639557, 'created': 1697683288.8639557, 'access': 1697602943.1846778, 'name': '.DS_Store', 'size': 6148, 'abspath': '/Users/YOU/Downloads/.DS_Store', 'dirname': '/Users/YOU/Downloads', 'is_dir': False, 'is_file': True, 'is_link': False, 'exists': True, 'ext': 'DS_Store'}, {'modified': 1690685751.342114, 'created': 1690685751.4194765, 'access': 1690685751.342114, 'name': '.localized', 'size': 0, 'abspath': '/Users/YOU/Downloads/.localized', 'dirname': '/Users/YOU/Downloads', 'is_dir': False, 'is_file': True, 'is_link': False, 'exists': True, 'ext': 'localized'}, {'modified': 1695535334.1411633, 'created': 1697604128.7045012, 'access': 1697604129.781534, 'name': 'CLI.py', 'size': 3345, 'abspath': '/Users/YOU/Downloads/CLI.py', 'dirname': '/Users/YOU/Downloads', 'is_dir': False, 'is_file': True, 'is_link': False, 'exists': True, 'ext': 'py'}, {'modified': 1697605101.6574, 'created': 1697683292.4821024, 'access': 1697683294.46923, 'name': 'Python_Logo.png', 'size': 747809, 'abspath': '/Users/YOU/Downloads/Python_Logo.png', 'dirname': '/Users/YOU/Downloads', 'is_dir': False, 'is_file': True, 'is_link': False, 'exists': True, 'ext': 'png'}, {'modified': 1697681746.0940206, 'created': 1697682027.268841, 'access': 1697682292.5433743, 'name': 'Sample_File.py', 'size': 1031, 'abspath': '/Users/YOU/Downloads/Sample_File.py', 'dirname': '/Users/YOU/Downloads', 'is_dir': False, 'is_file': True, 'is_link': False, 'exists': True, 'ext': 'py'}]

Copyright © 2023 Bisneto Inc. All rights reserved.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

filesystempro-0.0.0.2.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

filesystempro-0.0.0.2-py2-none-any.whl (8.5 kB view details)

Uploaded Python 2

File details

Details for the file filesystempro-0.0.0.2.tar.gz.

File metadata

  • Download URL: filesystempro-0.0.0.2.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.0

File hashes

Hashes for filesystempro-0.0.0.2.tar.gz
Algorithm Hash digest
SHA256 5cb2860d85dd46a5bc79253d9b630c01b1a4e3c4a0ef8aca7748682108307afa
MD5 f6aa96ffb2b2f42780165edd3a36e78b
BLAKE2b-256 6e13d74493b76e8dc30fdb84dfe02e234819ec48f28ff44356e27eb946e02304

See more details on using hashes here.

File details

Details for the file filesystempro-0.0.0.2-py2-none-any.whl.

File metadata

File hashes

Hashes for filesystempro-0.0.0.2-py2-none-any.whl
Algorithm Hash digest
SHA256 82b46557686b32f3ec9ad51fe59ba5fbe0ff5052a63241897bea86f708d04d06
MD5 661cf2907bd08fbcfce811eee73267d3
BLAKE2b-256 51cfc631cd9b6eaf72ec02ac7b31003cdad2783f5433ed784446ed4d42e4fd26

See more details on using hashes here.

Supported by

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