move()

audeer.move(src_path, dst_path)[source]

Move a file or folder independent of operating system.

As os.rename() works differently under Unix and Windows and shutil.move() can be slow, we use os.replace() to move the file/folder.

Parameters
  • src_path – source file/folder path

  • dst_path – destination file/folder path

Raises
  • OSError – if src_path is a file and dst_path is an existing folder

  • OSError – if src_path is a folder and dst_path is an existing file (not raised under Windows)

  • OSError – if dst_path is a non-empty folder, different from src_path, and src_path is also a folder

  • OSError – if dst_path is an empty folder, different from src_path and src_path is also a folder (raised only under Windows)

Examples

>>> path = mkdir("folder")
>>> src_path = touch(path, "file1")
>>> dst_path = os.path.join(path, "file2")
>>> move(src_path, dst_path)
>>> list_file_names(path, basenames=True)
['file2']