模拟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"] = " ...
随机推荐
- c# string 扩展方法
场景:只显示一字符串的前50个字符,多余的用“...”省略号替代 如果不用扩展方法当然也可以实现,写一个静态方法,如下: public class StringUtil { /// <summa ...
- SSAS下玩转PowerShell
操作SSAS数据库的方法有非常多,是否有一种能够方法能够通过脚本自己主动去做这些事呢,比方处理分区,创建备份以及监视SSAS的执行状况. 原文地址: http://www.mssqltips ...
- LVS集群简介及使用
什么是集群 一组通过高速网络互联的计算组,并以单一系统的模式加以管理 将很多服务器集中在一起,提供一种服务,在客户端看来就象是只有一个服务器 可以在付出较低成本的情况下获得在性能,可靠性,灵活性方面的 ...
- 【SVM、决策树、adaboost、LR对比】
一.SVM 1.应用场景: 文本和图像分类. 2.优点: 分类效果好:有效处理高维空间的数据:无局部最小值问题:不易过拟合(模型中含有L2正则项): 3.缺点: 样本数据量较大需要较长训练时间:噪声不 ...
- HBase 数据迁移方案介绍 (转载)
原文地址:https://www.cnblogs.com/ballwql/p/hbase_data_transfer.html 一.前言 HBase数据迁移是很常见的操作,目前业界主要的迁移方式主要分 ...
- golang 获取get参数
package main import ( "log" "net/http" ) func main() { http.HandleFunc("/&q ...
- [LeetCode] 130. Surrounded Regions_Medium tag: DFS/BFS
Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'. A reg ...
- Please add or free up more resources then turn off safe mode manually.
解决方案:硬盘满了,释放硬盘空间.
- 22.用demo通过点击切换图片路径
用demo通过点击切换图片路径 html: <img src="images/driving.png" class="driving"/> js: ...
- C++二进制字符串转十六进制字符串 十六进制字符串转二进制字符串
============================================== 二进制转十六进制 ============================================ ...