本文整理汇总了Python中unipath.Path.move方法的典型用法代码示例。如果您正苦于以下问题:Python Path.move方法的具体用法?Python Path.move怎么用?Python Path.move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unipath.Path
的用法示例。
在下文中一共展示了Path.move方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: move_subtitle_files
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import move [as 别名]
def move_subtitle_files(self, sorter_file):
"""Check for existing subtitle files matching media file and move
them to sort folder too.
"""
for ext in ('.srt', '.sub', '.idx'):
subtitle_path = Path(sorter_file.path.parent, '{}{}'.format(
sorter_file.path.stem, ext))
if subtitle_path.exists():
log.info('Moving subtitle file {} to {}'.format(
self.relative_path(subtitle_path, self.sort_dir),
sorter_file.season_dir))
subtitle_path.move(Path(self.sort_dir,
sorter_file.season_dir))
示例2: process_zip
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import move [as 别名]
def process_zip(self, zip_file_path):
"""Process the subtitle zip and extract all files with a valid file
extension. Remove the zip file when done.
"""
# Make sure the downloaded zip file is valid
if not zipfile.is_zipfile(zip_file_path):
log.info('Invalid zip file {}'.format(
SubtitleDownloader.relative_path(zip_file_path,
self.download_dir)))
zip_file_path.remove()
return False
zip_file = zipfile.ZipFile(zip_file_path)
for file in zip_file.namelist():
file = Path(file)
# Check file extension
if not file.ext.lower() in ('.srt'):
log.debug('Invalid subtitle file extension {}, '
'skipping'.format(file))
continue
# Name of unpacked subtitle file and the renamed subtitle file
unpacked_subtitle_file = Path(self.download_dir, file)
renamed_subtitle_file = Path(self.download_dir, '{}{}'.format(
self.name, unpacked_subtitle_file.ext.lower()))
# Skip the subtitle file if it's already exists
if renamed_subtitle_file.exists():
log.info('{} already exists'.format(
SubtitleDownloader.relative_path(renamed_subtitle_file,
self.download_dir)))
continue
# Extract the file to unpack dir and then move it to match the name
# of the subtitle search
log.info('Found subtitle, extracting subtitle file {}'.format(
SubtitleDownloader.relative_path(renamed_subtitle_file,
self.download_dir)))
zip_file.extract(file, self.download_dir)
unpacked_subtitle_file.move(renamed_subtitle_file)
# Remove the zip file
zip_file_path.remove()