qdyn.shutil module

Summary

Functions:

chdir

Change directory.

find_files

Iterate (recursively) over all the files matching the shell pattern (‘*’ will yield all files) in the given directory.

mkdir

Implementation of ‘mkdir -p’: Creates folder with the given name and the given permissions (mode)

tail

Print the last n lines of the given file

touch

Touch a filename (similar to the unix ‘touch’ utility).

Reference

qdyn.shutil.mkdir(name, mode=488)[source]

Implementation of ‘mkdir -p’: Creates folder with the given name and the given permissions (mode)

  • Create missing parents folder

  • Do nothing if the folder with the given name already exists

  • Raise OSError if there is already a file with the given name

qdyn.shutil.touch(fname)[source]

Touch a filename (similar to the unix ‘touch’ utility). If the file does not exist already, create it. Otherwise, update its access time.

qdyn.shutil.find_files(directory, pattern)[source]

Iterate (recursively) over all the files matching the shell pattern (‘*’ will yield all files) in the given directory. There is no guarantee on the order in which files are processed

>>> files = ["find_files_test/a.txt", "find_files_test/a.dat",
...          "find_files_test/sub/b.txt", "find_files_test/sub/c.txt"]
>>> mkdir("find_files_test/sub")
>>> for file in files:
...     touch(file)
>>> found_files = set()
>>> for file in find_files("find_files_test", '*.txt'):
...     found_files.add(file)
>>> for file in files:
...     if file.endswith('txt'):
...         assert file in found_files
...     else:
...         assert file not in found_files
>>> rmtree("find_files_test")
qdyn.shutil.chdir(dirname=None)[source]

Change directory.

Use as:

>>> mkdir('dir')
>>> with chdir('dir'):
...     pass
>>> rmdir('dir')
qdyn.shutil.tail(file, n)[source]

Print the last n lines of the given file