Skip to content

ellbur/quickfiles

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

This is a small file path manipulation DSL for Python.

Examples

from quickfiles import *

Find directory where script is located.

here = p(__file__).dir

tmp_dir = here / 'tmp'
tmp_dir.mkdir()

Make a unique file name with a prefix.

a = tmp_dir % COUNTER('hello')

Set the file's contents.

a.set('Hello, world!')

Read the file's contents.

print(a.read())

Two more unique file names, which are directories.

b1 = tmp_dir % COUNTER('hello')
b1.mkdir()

b2 = tmp_dir % COUNTER('hello')
b2.mkdir()

Make a file in that directory, with random name.

c1 = b1 % RAND('c', '.txt')
c1.set('Trapped in a file.')

Find the file with the same path relative to b2.

c2 = c1.replant(b1, b2)

Copy the contents over.

c1.cp(c2)

Verify that it got there.

print(c2.read())

Clean up.

tmp_dir.rm()

About

A small file pathname DSL in Python

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages