当前位置: 首页>>代码示例>>Python>>正文


Python Path.move方法代码示例

本文整理汇总了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))
开发者ID:dnxxx,项目名称:releasesorter,代码行数:17,代码来源:releasesorter.py

示例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()
开发者ID:dnxxx,项目名称:subtitledownloader,代码行数:47,代码来源:subtitledownloader.py


注:本文中的unipath.Path.move方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。