Top

tinypath module

API Documentation

Functions

def current_folder(

)

Returns the folder object of the currently running script

def current_script(

)

Returns the file object of the currently running script

def loop_folder(

folder, filetypes=[], maxdepth=None)

A generator that iterates through all files in a folder tree, either in a for loop or by using next() on it.

Arguments:

  • folder: The folder path to loop. Can be a folder instance, or any string path accepted by Folder.
  • filetypes (optional): If filetypes is a sequence then grabs all filetypes listed within it, otherwise grabs everything. Each file type is specified as the file extension including the dot, eg ".py".
  • maxdepth (optional): Max depth to look before continuing.

def path2obj(

path)

Returns a File or Folder object from the given path.

Classes

class File

A class that holds info about a file, which can be accessed via attributes.

Attributes:

  • path: Full proper path of the folder.
  • name: Just the name of the folder.
  • type: Type extension of the file.
  • filename: Name with type extension.
  • exists: True or False if exists.
  • read_ok: Read permission or not.
  • write_ok: Write permission or not.
  • size: Size instance of the size of the file.
  • lastchanged: The last time the file was modified as a timestamp object.

Ancestors (in MRO)

Methods

def __init__(

self, *filepath, **kwargs)

Arguments:

  • filepath: can be a relative path, a full path incl drive letter and filetype extension, or a list of path name elements to be joined together

class Folder

A class that holds info about a folder, which can be accessed via attributes

Attributes:

  • path: Full proper path of the folder.
  • name: Just the name of the folder.
  • exists: True or False if exists.
  • read_ok: Read permission or not.
  • write_ok: Write permission or not.
  • location: The parent folder where the folder is located.
  • content: A list of all child files and folders.
  • files: A list of all child files.
  • folders: A list of all child folders.
  • size: A Size instance of the total size of the entire folder. This is done by looping and sizign all nested child files, so can take a while for a high level folder. The size is cached after the first time to ease repeat calling.
  • total_files: Total number of files within the entire folder.

Ancestors (in MRO)

Methods

def __init__(

self, *folderpath, **kwargs)

Arguments:

  • folderpath: can be a relative path, a full path incl drive letter and filetype extension, or a list of path name elements to be joined together

def down(

self, foldername)

Changes this object's path down into the given subfolder name

def loop(

self, filetypes=[], maxdepth=None)

Loops files only

Arguments:

  • filetypes (optional): If filetype is a sequence then grabs all filetypes listed within it, otherwise grabs everything. Each file type is specified as the file extension including the dot, eg ".py".
  • maxdepth (optional): Max depth to look before continuing.

def overview(

self, filetypes=[], maxdepth=None)

Return a string representation of the folder structure and file members, as a snapshot of the folder's content.

Arguments:

  • filetypes (optional): If filetypes is a sequence then grabs all filetypes listed within it, otherwise grabs everything. Each file type is specified as the file extension including the dot, eg ".py".
  • maxdepth (optional): Max depth to look before continuing.

def overview_table(

self, filetypes=[], maxdepth=None)

Return a tab-delimited table string of the folder structure and file members, as a snapshot of the folder's content.

Arguments:

  • filetypes (optional): If filetypes is a sequence then grabs all filetypes listed within it, otherwise grabs everything. Each file type is specified as the file extension including the dot, eg ".py".
  • maxdepth (optional): Max depth to look before continuing.

Warning: Not fully tested...

def up(

self)

Changes this object's path up one level

class Size

The file size object, as returned by File.size.

Attributes:

  • bytes: The actual size in bytes, to be used for calculations.
  • string: The size as a more sensible human-readable string depending on size.

Ancestors (in MRO)

Methods

def __init__(

self, bytes)