Python实践: 360壁纸提取脚本

学习场景

获取壁纸软件的缓存文件到指定目录

效果

复制过程

在这里插入图片描述

源码

from shutil import copy2
from pathlib import Path
from os import listdir, path
from sys import exit


class Rename:
	def __init__(self, src=None, dst=None, suffix=None):
		"""

		:param src: 源文件夹路径
		:param dst: 目标文件夹路径
		:param suffix: 后缀名
		"""
		self.src = src
		if src is None:
			self.src = Path(Path.home()).joinpath("AppData/Roaming/360browser/bkinfo")
		self.dst = dst
		if dst is None:
			self.dst = Path(Path.home()).joinpath("Pictures/bg")
		self.suffix = "."+str(suffix)
		if suffix is None:
			self.suffix = ".jpg"
		self.fileList = []

	def exists(self):
		s = Path(self.src)
		if not s.exists():
			print("源路径不存在")
			exit(1)
		d = Path(self.dst)
		if not d.exists():
			d.mkdir()

	def get(self):
		self.fileList = listdir(self.src)
		if len(self.fileList) == 0:
			print("源文件夹找不到文件")
		for i in self.fileList:
			f = Path(self.src).joinpath(str(i))
			# print(f)
			if path.isdir(f):
				print("移除: ", i)
				self.fileList.remove(i)

	def copy(self):
		for i in self.fileList:
			src = Path(self.src).joinpath(i)
			dst = Path(self.dst).joinpath(i+self.suffix)
			print(src, "->", dst)
			try:
				copy2(src, dst)
			except Exception as e:
				print(e)

	def start(self):
		self.exists()
		self.get()
		self.copy()


# 按间距中的绿色按钮以运行脚本。
if __name__ == '__main__':
	r = Rename()
	r.start()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

坐公交也用券

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值