Skip to main content

Cross-platform file handling utilities.

Project description

File Handling

Cross-platform file handling utilities.

Hierarchy

filehandling
|---- path
|   |---- temp_dir
|   |---- abs_cwd
|   |---- abs_dir
|   '---- join_path
'---- file
    |---- read
    |---- write
    '---- Writer

Example

python

from filehandling import *

# absolute current working directory
print(abs_cwd(), flush=True)
# specify an inspect stack depth
print(abs_cwd(depth=2), flush=True)

# absolute directory of somefile
print(abs_dir("somefile"), flush=True)

# join path and normalize it
print(join_path(abs_cwd(), "..", "somefile"), flush=True)

# temporary directory of a bundled python application
print(temp_dir(), flush=True)

# read file content with automatic encoding detection
print(read("somefile"), flush=True)
# specify an encoding
print(read("somefile", "ascii"), flush=True)

# write content to file with attempts to use file queue
write("somefile", "ab", "test\n")  # fallback to open()
write("somefile", "wb", b"test\n")  # fallback to open()

# Writer file queue
writer = Writer(server=True)
ss = SS(functions=dict(write=lambda args: writer.fileq.put(args)))
ss_thread = threading.Thread(target=ss.start)
ss_thread.daemon = True
ss_thread.start()
# direct dispatch with a tuple
writer.fileq.put(("somefile", "ab", "test\n"))
# use file queue
write("somefile", "wb", b"test\n")

shell

rem filehandling.exe <function name> [argument] ...
filehandling.exe abs_cwd
filehandling.exe abs_cwd 2
filehandling.exe abs_dir somefile
filehandling.exe join_path C:\test .. somefile
filehandling.exe write file_path wb test1234
filehandling.exe write file_path ab test1234
rem the followings will fail to execute
filehandling.exe temp_dir
filehandling.exe read file_path
filehandling.exe read file_path ascii

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

omnitools-0.0.1.tar.gz (2.9 kB view hashes)

Uploaded Source

Built Distribution

omnitools-0.0.1-py3-none-any.whl (15.6 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