text stringlengths 0 828 |
|---|
4118,"def rmdir(self, parents=False): |
""""""Removes this directory, provided it is empty. |
Use :func:`~rpaths.Path.rmtree` if it might still contain files. |
:param parents: If set to True, it will also destroy every empty |
directory above it until an error is encountered. |
"""""" |
if parents: |
os.removedirs(self.path) |
else: |
os.rmdir(self.path)" |
4119,"def rename(self, new, parents=False): |
""""""Renames this path to the given new location. |
:param new: New path where to move this one. |
:param parents: If set to True, it will create the parent directories |
of the target if they don't exist. |
"""""" |
if parents: |
os.renames(self.path, self._to_backend(new)) |
else: |
os.rename(self.path, self._to_backend(new))" |
4120,"def copyfile(self, target): |
""""""Copies this file to the given `target` location. |
"""""" |
shutil.copyfile(self.path, self._to_backend(target))" |
4121,"def copymode(self, target): |
""""""Copies the mode of this file on the `target` file. |
The owner is not copied. |
"""""" |
shutil.copymode(self.path, self._to_backend(target))" |
4122,"def copystat(self, target): |
""""""Copies the permissions, times and flags from this to the `target`. |
The owner is not copied. |
"""""" |
shutil.copystat(self.path, self._to_backend(target))" |
4123,"def copy(self, target): |
""""""Copies this file the `target`, which might be a directory. |
The permissions are copied. |
"""""" |
shutil.copy(self.path, self._to_backend(target))" |
4124,"def copytree(self, target, symlinks=False): |
""""""Recursively copies this directory to the `target` location. |
The permissions and times are copied (like |
:meth:`~rpaths.Path.copystat`). |
If the optional `symlinks` flag is true, symbolic links in the source |
tree result in symbolic links in the destination tree; if it is false, |
the contents of the files pointed to by symbolic links are copied. |
"""""" |
shutil.copytree(self.path, self._to_backend(target), symlinks)" |
4125,"def move(self, target): |
""""""Recursively moves a file or directory to the given target location. |
"""""" |
shutil.move(self.path, self._to_backend(target))" |
4126,"def open(self, mode='r', name=None, **kwargs): |
""""""Opens this file, or a file under this directory. |
``path.open(mode, name)`` is a shortcut for ``(path/name).open(mode)``. |
Note that this uses :func:`io.open()` which behaves differently from |
:func:`open()` on Python 2; see the appropriate documentation. |
:param name: Path component to append to this path before opening the |
file. |
"""""" |
if name is not None: |
return io.open((self / name).path, mode=mode, **kwargs) |
else: |
return io.open(self.path, mode=mode, **kwargs)" |
4127,"def rewrite(self, mode='r', name=None, temp=None, tempext='~', **kwargs): |
r""""""Replaces this file with new content. |
This context manager gives you two file objects, (r, w), where r is |
readable and has the current content of the file, and w is writable |
and will replace the file at the end of the context (unless an |
exception is raised, in which case it is rolled back). |
Keyword arguments will be used for both files, unless they are prefixed |
with ``read_`` or ``write_``. For instance:: |
with Path('test.txt').rewrite(read_newline='\n', |
write_newline='\r\n') as (r, w): |
w.write(r.read()) |
:param name: Path component to append to this path before opening the |
file. |
:param temp: Temporary file name to write, and then move over this one. |
By default it's this filename with a ``~`` suffix. |
:param tempext: Extension to add to this file to get the temporary file |
to write then move over this one. Defaults to ``~``. |
"""""" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.