PSCF v1.1
Classes | Functions
pscfpp.file Namespace Reference

Utilities for manipulating files and paths. More...

Classes

class  Directory
 Class that represents a directory. More...
 
class  File
 Class that contains metadata for a file. More...
 

Functions

def relative_path (path1, path2)
 Generates relative path of path2 relative to path1. More...
 
def chdirs (dir)
 Change current working directory and create dir if necessary. More...
 
def open_w (path)
 Open file with specified path for writing, return file object. More...
 
def rm (path)
 Remove a file if possible (if the path exists and it is a file). More...
 
def mv (old_path, new_path)
 Rename a file or directory, creating any necessary parent directories. More...
 

Detailed Description

Utilities for manipulating files and paths.

Function Documentation

◆ relative_path()

def pscfpp.file.relative_path (   path1,
  path2 
)

Generates relative path of path2 relative to path1.

The paths path1 and path2 must be either absolute paths or relative paths defined relative to the same directory.

Parameters
path1reference path
path2path of interest
Returns
Path for file2 relative to directory containing path1

Definition at line 18 of file file.py.

◆ chdirs()

def pscfpp.file.chdirs (   dir)

Change current working directory and create dir if necessary.

This function attempts to change the current working directory to the directory specified by argument dir (like os.chdir), but first checks if the directory exists, and creates the directory and any missing parent directories if these do not yet exist.

Parameters
dirdirectory to change to

Definition at line 42 of file file.py.

◆ open_w()

def pscfpp.file.open_w (   path)

Open file with specified path for writing, return file object.

Similar to built-in function open(path,'w'), except that open_w will create any non-existent directories in the path as needed.

Parameters
pathpath for new file

Definition at line 57 of file file.py.

Referenced by pscfpp.make.MakeMaker.find().

◆ rm()

def pscfpp.file.rm (   path)

Remove a file if possible (if the path exists and it is a file).

This function exits silently, without throwing an exception or returning an error code, if the file does not exist or is not a file.

Parameters
pathpath to file to be removed

Definition at line 73 of file file.py.

◆ mv()

def pscfpp.file.mv (   old_path,
  new_path 
)

Rename a file or directory, creating any necessary parent directories.

Rename a file or directory. Similar to os.rename, except that this function will create any non-existent directories in the new path as needed.

Parameters
old_pathpath of file or directory to be renamed
new_pathnew path for file or directory

Definition at line 88 of file file.py.