Porter: Simple File Operations in Python
Project description
Porter
Porter provides simple file operations.
License
MIT.
Installation
Using pip:
pip install porter
File management
Import porter:
import porter
Create a folder:
porter.mkdir('/foo/bar')
# The new directory 'bar' will be created.
Rename a file/directory:
porter.rename('/foo/bar.txt', 'file.txt')
>>> '/foo/file.txt'
porter.rename('/foo/bar', 'folder')
>>> '/foo/folder'
Remove a file/directory:
porter.remove('/foo/bar')
Copy a file/directory:
# Two ways same result
porter.copy('/foo/bar.txt', '/foo1/bar.txt')
porter.copy_to('/foo/bar.txt', '/foo1')
Move a file/directory:
# Two ways same result
porter.move('/foo/bar', '/foo1/bar')
>>> '/foo1/bar'
porter.move_to('/foo/bar', '/foo1')
>>> '/foo1/bar'
Ignore and force:
porter.mkdir('/foo/bar', ignore=True)
# If '/foo/bar' exists, porter will not create the folder and no error will occur.
# Ignore option can ONLY ignore the error of the existing destination file/directory.
porter.move('/foo/bar', '/foo1/bar', force=True)
# If '/foo1/bar' exists, porter will move the directory anyway.
Ignore and force are both available in ‘mkdir’, ‘copy’, ‘copy_to’, ‘move’, ‘move_to’ functions.
Archive:
porter.archive('/foo/bar')
>>> '/foo/bar.tar'
porter.archive('/foo/bar', 'archive', 'zip')
>>> '/foo/archive.zip'
porter.archive_to('/foo/bar', '/foo/bar1', 'archive')
>>> '/foo/bar1/archive.tar'
All supported archive types: ‘gztar’, ‘bztar’, ‘tar’, ‘zip’
class TargetFile:
bar = porter.TargetFile('/foo/bar.txt')
bar.src
>>> '/foo/bar.txt'
bar.name
>>> 'bar'
bar.ext
>>> 'txt'
bar.move_to('foo1')
bar.src
>>> '/foo1/bar.txt'
bar.remove()
# Then it will be removed.
class TargetDirectory:
"""
The structure of the directory:
- foo
- bar
- dir1
- f1.txt
- dir2
- f2.txt
- foo1
"""
bar = porter.TargetDirectory('/foo/bar')
bar.src
>>> '/foo/bar'
bar.list()
>>> {'dir1': {'f1.txt': None}, 'dir2': {'f2.txt': None}}
bar.files()
>>> ['f1.txt', 'f2.txt']
bar.directories()
>>> ['dir1', 'dir2']
bar.move_to('foo1')
bar.src
>>> '/foo1/bar'
bar.empty()
# All of the files in it will be removed
bar.remove()
# Then it will be removed.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file porter-0.1.5.tar.gz.
File metadata
- Download URL: porter-0.1.5.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06e879bee63d13f4919cb7682eb58b299e4483c0c312a1f60a5abeb2f2785ea8
|
|
| MD5 |
42d47582c6d74be934f578d229e4d793
|
|
| BLAKE2b-256 |
b4e9a3b40a574aae27c2bd5504ef9129d5d822bd2b6888e53654f99cf565c194
|
File details
Details for the file porter-0.1.5-py2.7.egg.
File metadata
- Download URL: porter-0.1.5-py2.7.egg
- Upload date:
- Size: 6.7 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4500bc2e5c94b703f6d04d3026c552d1778817e4b308bcfbd628f464f22a687a
|
|
| MD5 |
ca962d0652d7119ae56fe276c9f7481f
|
|
| BLAKE2b-256 |
e34acdfc43a80d26fdc93cc22dc62fe70125a7c11f7488d1643c582a5c54e8c1
|