網站首頁 編程語言 正文
前言
經常使用電腦自帶的搜索很慢很卡,今天做一個搜索工具,可以搜索到隱藏的文件,而且速度也很快
步驟
導入模塊
import os
檢測一下輸入的路徑最后一位有沒有/,如果沒有則添加,是為了方便操作
if DIR.endswith('/') == True: pass else: DIR = DIR+'/'
用來循環檢測文件,進入文件目錄然后檢測,再次進入檢測,循環往復
def iterbrowse(path): for home, dirs, files in os.walk(path): for filename in files: yield os.path.join(home, filename)
用來將路徑的\\改為/,也是為了方便軟件識別
NAME = fullname.replace("\\", "/") # 替換
檢測你要查找的文件名稱是否存在,如果存在則打印出來,列,查找text,則會打印出關于text的所有文件,包含:textwet.*,sdftext.*,*.text
os.path.basename(NAME)? 用來提取文件名不含路徑,
inpu in os.path.basename(NAME)? ?用來檢測os.path.basename(NAME)里是否含有inpu(值)
os.path.isfile(NAME)? ? 用于檢測文件是否存在
if (inpu in os.path.basename(NAME)) == True: if os.path.isfile(NAME) == True: print(NAME)
操作如下:
輸入路徑,輸入要搜索的名稱,可以看到已經搜索出來了
完整代碼:
import os DIR = input('輸入路徑:') inpu = input('輸入關鍵字:') if DIR.endswith('/') == True: pass else: DIR = DIR+'/' def iterbrowse(path): for home, dirs, files in os.walk(path): for filename in files: yield os.path.join(home, filename) for fullname in iterbrowse(DIR): NAME = fullname.replace("\\", "/") # 替換 if (inpu in os.path.basename(NAME)) == True: if os.path.isfile(NAME) == True: print(NAME)
總結
原文鏈接:https://blog.csdn.net/weixin_46625757/article/details/122459784
相關推薦
- 2022-02-24 Golang?strings包常用字符串操作函數_Golang
- 2023-11-22 Linux Ubuntu Linux中建立、復制、移動、刪除文件的命令
- 2022-03-31 C#客戶端HttpClient請求認證及數據傳輸_C#教程
- 2022-09-13 Python使用os模塊實現更高效地讀寫文件_python
- 2022-01-26 maatwebsite/Excel 導入 iconv (): Detected an illegal
- 2022-04-08 Android接入阿里云熱修復介紹_Android
- 2022-08-27 JQuery自定義模態框效果_jquery
- 2022-09-05 SparkStreaming寫入Hive慢
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支