在os模组中使用rename()更改档名
path = "./videos"
bname = "video"
count = 1
for fname in os.listdir(path):
s_name = os.path.join(path, fname)
name = os.path.splitext(fname)
new_fname = bame + str(count) + name[1]
count = count + 1
(s_fname为原始档案全名,呼叫os.path.splitext()分割档名和副档名)
new_fname = os.path.join(path, new_fname)
print(s_fname, new_fname)
os.rename(s_fname, new_fname)
path = "./jpgs"
for root, dirs., files in os.walk(path):
print(root)
for fname in files:
print(os.path.join(root, fname)
shutil模组可以使用copytree(A,B),将参数目录A的所有档案复制到目录B
path = "./figures"
shutil.rmtree(path) #rmtree()可以将参数目录下所有档案和子目录都删除掉
move(A,B)可以移动档案或整个目录(参数AB可以是档案或目录)
<<: Day26 用python写UI-聊聊Text(三)
>>: [ Day 26 ] 实作一个 React.js 网站 2/5
你喜欢什麽类型? | 实质的那一种 | $$$$$$爱了 🐄点此填写今日份随堂测验 ...
一. 前言 前一天已经说明N-gram的一些计算方式了,这篇会以实作'预测词'来作为N-gram的范...
昨天介绍了Node.js,今天我们就要来实际安装Node.js啦 首先当然是到官网去下载Node.j...
这礼拜进度开始落後,在写第七周作业的 todo list,自己後来才发现事件代理的用法,所以後面又重...
我们从做中学, 就用Bootstrap 5来复刻赫赫有名的甜点电商切版作业其中一部分的功能吧。 如果...