Skip to main content

The main function of this small package is to process the contents of a folder with a single function: folder.process() (pun intended :-), without going into the details of iterating over files and folders.

It’s strange that python doesn’t have such a built-in function, but maybe someone (maybe even myself) will write an extension to c someday.

So, if, for example, you need to find all files with a too long full name, you just need to write the following script:

from argparse import ArgumentParser
from py_fso import folder

MAX_FILEPATH_LENGTH = 260

def print_if_file_has_length_too_more_chars(fileEntry) :
    filePath = fileEntry.path
    fileLength = len(filePath)
    if fileLength > MAX_FILEPATH_LENGTH:
        print("File " + filePath + " has  length " + str(fileLength) + " chars")

parser = ArgumentParser(description='Scan a directory and its subdirectories and search for files with path lengths greater than ' + str(MAX_FILEPATH_LENGTH) + ' characters.')
parser.add_argument("directory", help="scan this directory with its subdirectories", metavar="DIR")
parser.add_argument("-m", "--max_filepath_length", help="max file path's length")
args = parser.parse_args()
if args.max_filepath_length:
    MAX_FILEPATH_LENGTH = int(args.max_filepath_length)

folder.process(init_dir = args.directory, proc_file_function = print_if_file_has_length_too_more_chars, process_dirs = False, proc_dir_function = '', go_into_subdirs = True)

Just one call to folder.process() will replace all the details of traversing the contents of the folder, allowing you to focus on the main action of the script.

The package also includes several useful functions for working with text files.

I use this package all the time in my work, installing it globally so that it’s available to all scripts. It’s very convenient.

Getting Started

Prerequisites

  • python (version >=3+, version 2+ doesn’t check)

Installing

# Just install the package globally (recommended)
# so you can use in all your scripts and projects:
$ python -m pip install py_fso

Using

# then you can use it in your scripts
from py_fso import folder
from py_fso import textfile

One more script example

#!/usr/bin/python
# -*- coding: utf-8 -*-
""" Try to find  all files in the folder of a site including sub-folders which are not UTF-8 encoded."""

import chardet
import os.path
from py_fso import folder

fileListExtensions = ["htm", "html", "php", "css", "js"]

def print_if_file_code_page_not_utf8(fileEntry) :
    filePath = fileEntry.path
    if os.path.splitext(filePath)[1][1:].strip().lower() in fileListExtensions:
        with open(filePath, "rb") as F:
            text = F.read()
            enc = chardet.detect(text).get("encoding")
            if enc and enc.lower() != "utf-8":
                print("File " + filePath + " might not be UTF-8 encoded")

folder.process("path\\to\\your\\site\\folder", proc_file_function = print_if_file_code_page_not_utf8, process_dirs = False, proc_dir_function = None, go_into_subdirs = True)

Versioning

Using SemVer for versioning.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Metadata

Release files for py-fso 1.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for py-fso 1.0.8
File Interpreter ABI Platform Actions
py_fso-1.0.8-py3-none-any.whl Python 3 none any Details for py_fso-1.0.8-py3-none-any.whl

Release files / py_fso-1.0.8-py3-none-any.whl

Download URL py_fso-1.0.8-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b2c2d92604506757071d50368e115f2d5039a658e68b8b4cf202b2de2eff1893
BLAKE2b-256 checksum
How to use checksums
b87c26e1a228c7e3c5fe6d7907d863976561b265f2cddc5a9bb6bc78efbb4cb0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.2

Security for py-fso 1.0.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page