模拟windows全盘搜索
循环遍历pc上的文件夹,保存到mysql数据库中,搜索时,从数据库取数据。
import os
import datetime
import pymysql
import threading def link_db():
conn = pymysql.connect(host='localhost', port=3306, user='root', password='123456', db='win', charset='utf8mb4')
cursor = conn.cursor()
return cursor def save_file(path, conn, cursor): try:
print(path)
dirList = os.listdir(path)
for i in dirList:
if i.startswith('.'):
continue
newPath = os.path.join(path, i)
if os.path.isdir(newPath):
save_file(newPath, conn, cursor)
elif os.path.isfile(newPath):
# 名称
file_name = os.path.basename(newPath)
# 类型
file_type = os.path.splitext(newPath)[1]
# 完整路径
file_path = newPath
# 大小
file_size = os.path.getsize(newPath)
# 上次访问时间
last_time = datetime.datetime.fromtimestamp(os.path.getatime(newPath))
# 创建时间
create_time = datetime.datetime.fromtimestamp(os.path.getctime(newPath))
# 修改时间
update_time = datetime.datetime.fromtimestamp(os.path.getmtime(newPath))
sql = "insert into `files`(`file_name`, `file_type`, `file_path`, `file_size`, `last_time`, " \
"`create_time`, `update_time`) values(%s, %s, %s, %s, %s, %s, %s)"
cursor.execute(sql, (file_name, file_type, file_path, file_size, last_time, create_time, update_time))
conn.commit()
print(file_name , '文件名')
except FileNotFoundError as e:
pass
except PermissionError as e:
pass def search_file(name, conn, cursor):
sql = 'select file_name, file_path from files where file_name like "%{}%" ; '.format(name)
cursor.execute(sql)
data = cursor.fetchall()
for file in data:
print(file) if __name__ == '__main__':
conn = pymysql.connect(host='localhost', port=3306, user='root', password='123456', db='win', charset='utf8mb4')
cursor = conn.cursor()
# sql = 'delete from files;'
# cursor.execute(sql)
# conn.commit()
# path = 'D:\\'
# thread = threading.Thread(target=save_file, args=(path, conn, cursor), name='No.1')
# thread.start()
# thread.join()
file_name = input('输入搜索的文件名:')
thread1 = threading.Thread(target=search_file, args=(file_name, conn, cursor), name='search.one')
thread1.start()
# search_file(file_name, conn, cursor)
模拟windows全盘搜索的更多相关文章
- hdu4740【杭州网赛、模拟、有点搜索?】
当时看了这题就感觉so easy... 本来不想写的,后来感觉是不是可以练一下搜索水平.. 比赛时有人过了就没写. 比赛完了写一下. 实现还不是那么顺利, 囧 本来自己以为这题能练下搜 ...
- for /r命令实现全盘搜索指定文件
@echo off Rem :全盘搜索指定文件并输出到文本 set "fileName=Normal.dotm" set "outPutPath=C:\result.tx ...
- Ext js框架模拟Windows桌面菜单管理模板
一款超炫的后台,Ext模拟Windows桌面,Ext经典浅蓝风格,功能非常强大,包括最大化.最小化.状态栏.桌面图标等,不过需要非常懂Ext脚本的才可驾驭它. 1.图片 2. [代码][HTML] ...
- PCB 模拟Windows管理员域帐号安装软件
在我们PCB行业中,局域网的电脑一般都会加入域控的,这样可以方便集中管理用户权限,并可以对访问网络资源可以进行权限限制等. 由于加入了域控对帐号权限的管理,这样一来很多人都无权限安装软件,比如:PCB ...
- PCB 工程系统 模拟windows域帐号登入
一.需求描述: 对于PCB制造企业来说,基本都采用建立共享目享+域名管控权限,好像别的大多数行业都是这样的吧.呵呵 在实际应用中,经常会有这样的问题,自己登入的帐号没有共享目录的权限,但又想通过程序实 ...
- [CQOI2012]模拟工厂 题解(搜索+贪心)
[CQOI2012]模拟工厂 题解(搜索+贪心) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1327574 链接题目地址:洛谷P3161 BZOJ P26 ...
- Java模拟Windows的Event
场景 开发中遇到一个场景,业务操作会不定时的产生工作任务,这些工作任务需要放入到一个队列中,而另外会有一个线程一直检测这个队列,队列中有任务就从队列中取出并进行运算. 问题 业务场景倒是简单,只不过这 ...
- jsonp模拟获取百度搜索相关词汇
随便写了个jsonp模拟百度搜索相关词汇的小demo,帮助新手理解jsonp的用法. <!DOCTYPE html><html lang="en">< ...
- 【python-appium】模拟手机按键搜索异常
执行代码的过程中运行self.driver.press_keycode(84)设备没反映,则需要关闭#desired_caps["unicodeKeyboard"] = " ...
随机推荐
- weixin.com的whois信息变更为腾讯了 是准备替换weixin.qq.com吗?
微信双拼域名weixin.com的whois信息变更,所有人为腾讯.从weixin.com在10月18日这次的whois变更上,透露出腾讯似乎准备启用这个域名.如果启用,毋庸置疑是要应用在腾讯的巨无霸 ...
- Hive SQL测试
在spark的空表test上进行运算,注意结果差异: ,age)) as ages from test group by name;//空 ,age)) as ages from test group ...
- 发现Boost官方文档的一处错误(numpy的ndarray)
文档位置:https://www.boost.org/doc/libs/1_65_1/libs/python/doc/html/numpy/tutorial/ndarray.html shape在这里 ...
- Scala常用变量生命周期
val words = *** //在words被定义时取值 lazy val words = *** //在words被首次使用时取值 def words = *** //在每一次words被使用时 ...
- cloud-api-service和cloud-iopm-web提交merge方法
cloud-api-service应该push to '自己的分支',然后去gitserver请求合并 cloud-iopm-web(master分支)应该push to Upstream,然后去gi ...
- linux下automake用法
linux下automake用法 2017年02月06日 09:21:14 阅读数:3684 标签: makemakefilegnulinux 作为Linux下的程序开发人员,大家一定都遇到过Ma ...
- maven项目中添加Tomcat启动插件
在pom.xml文件中添加如下配置: <!-- 配置tomcat插件,pom.xml里配置 --> <build> <plugins> <plugin> ...
- AFNetworking 源码解析
3.0 之后,就取消了NSOperation的控制. 因为根据Apple Developer Document的文档 https://developer.apple.com/documentation ...
- 引:Jmeter添加变量的四种方法
一.在样本中添加同请求一起发送的参数.根据服务器设置的数据类型,来添加不同类型的参数 二.用户定义的变量 1.创建:添加->配置元件->用户定义的变量 2.作用:当前的线程组内所有Samp ...
- 解决PuTTY中文乱码
转载:http://lhdeyx.blog.163.com/blog/static/3181969720091115113716947/ 打开putty,选择 Category中的Windows--- ...