bag.pathlib_complement module

A subclass of Path from pathlib.

Python 3.4 introduces an object-oriented module for path manipulation called pathlib. But it is missing certain convenience methods.

class bag.pathlib_complement.Path[source]

Bases: pathlib.PosixPath

pathlib.Path subclass – has more methods.


Change the UNIX group of this path.


Remove directory contents without removing the directory itself.


Create the directory only if it does not yet exist.

recursive_chgrp(group, this=False)[source]

Change the UNIX group of the directory contents.

If this, changes the directory itself, too.

recursive_chmod(file_perms, dir_perms=None)[source]

Delete self, irrespective of whether it’s symlink, file or dir.

walk(filter=None, this=False)[source]

Recursively traverse this directory.


Given 4, returns 5. Given 6, returns 7.

Based on desired file permissions, returns corresponding dir permissions.


Given file_perms, return directory permissions.

Most people understand UNIX permissions for files, but not for directories – if a file has 644 then usually its parent should be 754. We automate this here.


Convert 3 numbers to be able to chmod.

Given a (string or int) representation of a file mode, such as “777” – you have to realize that is actually an octal number –, returns the corresponding integer to be able to chmod.