async def mv(self, ctx, source: str, dest: str): source_path = fileutils.PathBuilder(self._path, self._root)\ .join(source)\ .build() dest_path = fileutils.PathBuilder(self._path, self._root) \ .join(dest)\ .build() if not os.path.exists(dest_path): os.makedirs(dest_path, exist_ok=True) os.rename(source_path, dest_path) await reactions.confirmation(ctx.message)
async def get(self, ctx, path): target = fileutils.PathBuilder(self._path, self._root)\ .join(path)\ .build() if os.path.isfile(target): await ctx.send(file=nextcord.File(target)) else: await reactions.confusion(ctx.message, f'{target} is not a file')
async def cd(self, ctx, directory: str): next_path = fileutils.PathBuilder(self._path, self._root)\ .directory_only()\ .join(directory)\ .build() if next_path is None: await reactions.confusion(ctx.message) else: self._path = next_path await ctx.send(self._path)
async def mkfile(self, ctx, file_path: str): target = fileutils.PathBuilder(self._path, self._root).join(file_path) if len(ctx.message.attachments) <= 0: await reactions.confusion(ctx.message) return url = ctx.message.attachments[0].url file = await webutils.download_file(url) with open(target, 'wb') as fd: shutil.copyfileobj(file.raw, fd) await reactions.confirmation(ctx.message)
async def rmall(self, ctx, dirname: str): target = fileutils.PathBuilder(self._path, self._root) \ .join(dirname) \ .build() if os.path.isfile(target): os.remove(target) elif os.path.isdir(target): shutil.rmtree(target) else: await reactions.confusion( ctx.message, f'File {target} is not a regular file or directory') return await reactions.confirmation(ctx.message)
async def mkdir(self, ctx, name: str): os.mkdir(fileutils.PathBuilder(self._path, self._root).join(name)) await reactions.confirmation(ctx.message)