This commit is contained in:
louiscklaw
2025-02-01 01:19:51 +08:00
commit 3b0b154910
32597 changed files with 1171319 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
import os
import hashlib
def find_dup(dir):
files = {}
for root, _, filenames in os.walk(dir):
for f in filenames:
file_path = os.path.join(root, f)
with open(file_path, "rb") as file:
file_hash = hashlib.md5(file.read()).hexdigest()
if file_hash in files:
files[file_hash].append(file_path)
else:
files[file_hash] = [file_path]
for file_hash, file_paths in files.items():
if len(file_paths) > 1:
print("dup:", file_hash)
for file_path in file_paths:
os.remove(file_path)
if __name__ == "__main__":
find_dup("/home/logic/_wsl_workspace/comission-playlist/vinniesniper-54816/task1/_lab/003-crawler-bus/p/flower")

View File

@@ -0,0 +1,9 @@
# -*- coding:utf8 -*-
import os
# 生成路径列表文件
# os.system("dir /b/s/p/w *.jpg > neg.txt")
os.system("find " + os.path.abspath(os.curdir) + " -name '*.jpg' > neg.txt")
# os.system("pause")

View File

@@ -0,0 +1,46 @@
# -*- coding:utf8 -*-
import os
import re
import shutil
from pathlib2 import Path
import string
import random
# 批量命名图片
def renamePic(srcImgDir):
i=0
for item in srcImgDir.rglob("*.jpg"):
# 获取图片名
imgName = item.name
newName = str(i)+".jpg"
i=i+1
# 重命名
print(f"prepare to rename {imgName}")
item.rename(newName)
# 批量命名图片
def renamePicWithRandomName(srcImgDir):
for item in srcImgDir.rglob("*.jpg"):
# 获取图片名
imgName = item.name
# 生成随机字符串
random_str = ''.join(random.sample(string.ascii_letters + string.digits, 32))
# 生成随机数字
random_int = str(random.randint(0, 10000))
# 生成新的图片名
newName = random_str + random_int + ".jpg"
# 重命名
print(f"prepare to rename {imgName} to {newName}")
item.rename(newName)
if __name__ == '__main__':
# 文件路径--跟代码同目录
srcImgPath = Path("./")
renamePicWithRandomName(srcImgPath)
renamePic(srcImgPath)

View File

@@ -0,0 +1,8 @@
# -*- coding:utf8 -*-
import os
# os.system("copy .\\neg.txt ..\\")
os.system("cp ./neg.txt ../")
# os.system("pause")