Skip to content

Programming: Useful file tools in Python

Joshua Newton edited this page Jan 2, 2021 · 3 revisions

Most file commands can be found here and here

Most common file commands

  • cp filename path --> shutil.copy(filename, path)
  • rm -rf path --> shutil.rmtree(path, ignore_errors=True)
  • mv filepath1 filepath2 --> shutil.move(filepath1, filepath2)
    • Note: Do not use os.rename! Instead, use shutil.move for this too, because os.rename has an issue that causes problems with tmp_path on CI, as well as any users who have files spread across different filesystems.
  • status, path_sct = commands.getstatusoutput('echo $SCT_DIR') --> path_sct = os.environ.get('SCT_DIR')
Clone this wiki locally