給自己寫的乙個小工具,為了便於在**資料夾中,搜尋包含特定字串的檔名稱,方便debug時查詢一些功能。
之所以用lua是因為電腦上只有lua,懶得安裝別的了。
在cmd中,和search.lua同一路徑下,輸入lua search.lua "你想要查詢的字串",資料夾名字可在**中修改。
local lfs = require "lfs"
local io = require "io"
local string = require "string"
function searchforstringinwhichfile (path,finddata)
for file in lfs.dir(path) do
if file ~= "." and file ~= ".." and file ~=".svn" then
local f = path..'\\'..file
local attr = lfs.attributes (f)
assert (type(attr) == "table")
if attr.mode == "directory" then
searchforstringinwhichfile(f,finddata)
elseif attr.mode == "file" then
local file = io.open(f,"r")
local data = file:read("*a")
file:close()
if string.find(data,finddata) ~= nil then
print(f)
endend
endend
endfor i, v in ipairs(arg) do
if i == 1 then
find = v
endendsearchforstringinwhichfile("d:\\code",find)
Python列舉指定資料夾下的特定檔案
方案 1 利用 glob 模組 import glob import os dst path c ext name txt os.chdir dst path for file in glob.glob ext name pass 方案 2 利用 os.listdir import os dst p...
python找出資料夾下特定字尾檔案
實現功能 找出資料夾下特定字尾檔案 import os defscreen 函式功能為 篩選出資料夾下所有字尾名為.txt的檔案 path 此處填寫要篩選的資料夾位址名稱 資料夾位址 txt list 建立乙個空列表用於存放資料夾下所有字尾為.txt的檔名稱 file list os.listdir...
資料夾下Excel內容搜尋 Python
基於 pyqt5 和 xlrd 庫實現 當搜尋框為空時不進行搜尋 如下 import sys,os qfiledialog from pyqt5.qtgui import qicon from pyqt5.qt import qlineedit import xlrd def init self s...