文件批量加密重命名--python脚本AND mysql命令行导入数据库

时间:2023-03-10 00:44:06
文件批量加密重命名--python脚本AND mysql命令行导入数据库

在考试中学生交上来的报告,需要进行一下文件名加密,这样阅卷老师就不知道是谁的报告了

在百度帮助下,完成了加密和解密脚本,

加密

#!/usr/bin/python
# -*- coding: utf-8 -*- # coding:utf8
import os
import base64 def rename():
i = 0
path = "D://123"
path1 = "D://1234"
filelist = os.listdir(path) # 该文件夹下所有的文件(包括文件夹)
for files in filelist: # 遍历所有文件
i = i + 1
Olddir = os.path.join(path, files) # 原来的文件路径
#print Olddir
if os.path.isdir(Olddir): # 如果是文件夹则跳过
continue
filename = os.path.splitext(files)[0] # 文件名
#print filename
filetype = os.path.splitext(files)[1] # 文件扩展名
#print filetype
x=base64.b64encode(str(filename))
Newdir = os.path.join(path1, x + filetype) # 新的文件路径
# x=base64.b64encode(Olddir)
os.rename(Olddir, Newdir) # 重命名 rename()

解密

#!/usr/bin/python
# -*- coding: utf-8 -*- # coding:utf8
import os
import base64 def rename():
i = 0
path = "D://1234"
path1 = "D://123"
filelist = os.listdir(path) # 该文件夹下所有的文件(包括文件夹)
for files in filelist: # 遍历所有文件
i = i + 1
Olddir = os.path.join(path, files) # 原来的文件路径
#print Olddir
if os.path.isdir(Olddir): # 如果是文件夹则跳过
continue
filename = os.path.splitext(files)[0] # 文件名
#print filename
filetype = os.path.splitext(files)[1] # 文件扩展名
#print filetype
# x=base64.b64encode(str(filename))
x = base64.b64decode(str(filename))
Newdir = os.path.join(path1, x + filetype) # 新的文件路径
# x=base64.b64encode(Olddir)
os.rename(Olddir, Newdir) # 重命名 rename()

记一下用到的命令

mysql命令行导入数据库

create database 510cms  //创建数据库510cms

use 510cms              //进入数据库510cms
source 510cms.sql //将sql文件导入数据库510cms