OS Utilities

Some extended utility functions for ‘os’ module.

os_utils.cp_r(src, dst)[source]

Same effect as the unix command ‘cp -r src dst’, supporting the followings:

  1. cp_r(“/path/to/src_file”, “/path/to/”dst_file”): The ‘src_file’ is a single file, and ‘dst_file’ is created or overwritten if already exists.
  2. cp_r(“/path/to/src_folder”, “/path/to/dst_folder”): The ‘dst_folder’ is a single folder, and ‘dst_folder’ will be created if not already exists, otherwise a “/path/to/dst_folder/src_folder” will be created.
  3. cp_r(“/path/to/src”, “/path/to/dst_folder”): The ‘src’ can be either a file or a folder, and can contain wildcard characters (e.g. ‘*’), and the ‘dst_folder’ must already exist.
  4. cp_r([“/path/to/src1”, “/path/to/src2”, ...], “/path/to/dst_folder”): The ‘src’ can be anything as the previous syntax, and the first argument can be either list or tuple. The ‘dst_folder’ must already exist.
os_utils.mkdir_p(path, mode=511)[source]

Create a leaf directory ‘path’ and all intermediate ones.

No error will be reported if the directory already exists. Same effect as the unix command ‘mkdir -p path’.

os_utils.rm_rf(path)[source]

Remove a file or a directory, recursively.

No error will be reported if ‘path’ does not exist. The ‘path’ can be a list or tuple. Same effect as the unix command ‘rm -rf path’.