Python查詢涉密關鍵字檔案

2021-07-24 18:05:35 字數 2280 閱讀 1470

功能:
remove 資料夾是刪除當前檔案下的檔案

要實現乙個查詢關鍵字或者涉密檔案,找到然後刪除它自己定義乙個關鍵字,並且刪除它

print(os.remove('aa.html'))

檢視當前檔案方法 getcmd

# print(os.path)

print(os.path.abspath('.'))

print(os.getcwd())

#python

檔案是不是存在

# os.path.exists()

可以判斷檔案和目錄存在不

# filename = r'c:\users\20160330\desktop\pycode3.5-2.7\3.5\test1\mhz1.txt'

# if os.path.exists(filename):

# print("*****

檔案存在

*****")

# else:

# print("*********

檔案不存在

***xx")

下面的**可以檢視得到在檔案中的

importfnmatch,os

forfileinos.listdir("mhz3"):

iffnmatch.fnmatch(file,"*.png"):

print (file)

#定義乙個函式

defendwith(*endstring):

ends = endstring

defrun(s):

f = map(s.endswith,ends)

if true inf:

returns

returnrun

#把檔名遍歷出來

if__name__ =='__main__':

importos

list_file = os.listdir(r'c:/users/20160330/desktop/pycode3.5-2.7/3.5/test1/mhz3')

a = endwith('.txt','.py','.png')

f_file = filter(a, list_file)

foriinf_file:

print(i)

ifos.path.exists(r'.txt'):

os.remove(i)

print("檔案已刪除")

# elif i == '.py':

elifos.path.exists(r'.py'):

os.remove(i)

print("檔案已刪除")

# elif i == '.png':

elifos.path.exists(r'.png'):

os.remove(i)

else:

print("路徑輸入錯誤,重新輸入!")

如果是以png結尾的都刪除了

修改ifi =='.txt':

python批量刪除指定檔案

關鍵字查詢

題目描述 每次給你一篇文章,和一些關鍵字,需要你告訴我多少關鍵字將匹配於文章。輸入描述 第一行包含乙個整數,表示有多少篇文章。最後一行是文章,長度不超過1000000。輸出描述 輸出文章中包含多少關鍵字。輸入樣例 15 shehe sayshr heryasherhs 輸出樣例 3源 include...

AngularJS關鍵字查詢

按貨物數量反序排序 按貨物入庫時間正序排序 按貨物入庫時間反序排序 入庫貨物名稱 貨物數量 貨物產地 貨物單價 貨物入庫時間日期操作 刪除mo.controller myctrl function scope 刪除 scope.del function delname else 定義下拉列表的排序 ...

linux關鍵字查詢

指定單個檔案查詢 方法一 cat test.log grep 關鍵字 方法二 grep i 關鍵字 test.log 關鍵字查詢日誌,並顯示該條日誌的前後n 10 行記錄 cat test.log grep b10 a10 關鍵字 從當前目錄的所有.log檔案中查詢內容關鍵字是 test 檔案 fi...