Skip to main content

这是做什么的?

这是一个任意文件查找器,支持文件夹,文件名以及文件内容的关键字查找,支持正则模式,并且用突出颜色显示

怎么安装?

pip install findkw

怎么使用

1. 在终端直接使用:

$ findkw -k "要查找关键字" [-f --folder] [-o --filename_only] [-r --re_mode]

参数解释:

-h, --help ---> 显示帮助
-k, --keyword ---> 要查找的关键字,必须值
-f, --folder ---> 需要查找的文件夹,默认在运行目录下
-r, --re_mode ---> y/n 是否以正则方式查找,默认n,可不指定参数值
-o, --filename_only ---> y/n 是否只查找文件夹名和文件名,默认n,可不指定参数值
-rmf, --remove_file ---> y/n 是否删除找到的文件,默认n,可不指定参数值
-rml, --remove_line ---> y/n 是否删除找到的行,默认n,可不指定参数值
-qr, --quietly_remove ---> y/n 是否不经确认直接删除,默认n,可不指定参数值
-rt, --replace_to ---> 替换为,支持 python re.sub 的操作

示例:

# 当前文件夹下查找所有符合关键字的文件内容
$ findkw -k "good job"
# in file [ /root/Findkw/README.md ]: 
# >>> [ 36 ] [ $ findkw -k "good job" ]

# 上面输出的是当前 README 文件的第36行,找到了需要的关键字

# 在指定文件夹下查找关键字:
$ findkw -k "nice job" -f "/root/search_folder"

# 在当前文件夹下查找带有关键字的文件夹名或者文件名:
$ findkw -k "findkw" -o
# >>> [ folder ] [ /root/Findkw/findkw.egg-info ]
# >>> [ folder ] [ /root/Findkw/build/lib/findkw ]
# >>> [ file name ] [ /root/Findkw/findkw/findkw.py ]
# >>> [ folder ] [ /root/Findkw/findkw ]
# ...

# 正则模式查找所有以 .py 结尾的行:
$ findkw -k ".*?\.py$" -r
# in file [ /root/Findkw/findkw.egg-info/SOURCES.txt ]: 
# >>> [ 2 ] [ setup.py ]
# >>> [ 3 ] [ findkw/__init__.py ]
# >>> [ 4 ] [ findkw/findkw.py ]

# 正则模式查找所有以 .py 结尾的文件夹和文件名:
$ findkw -k ".*?\.py$" -r -o
# >>> [ file name ] [ /root/Findkw/setup.py ]
# >>> [ file name ] [ /root/Findkw/build/lib/findkw/findkw.py ]
# >>> [ file name ] [ /root/Findkw/build/lib/findkw/__init__.py ]
# >>> [ file name ] [ /root/Findkw/findkw/findkw.py ]
# >>> [ file name ] [ /root/Findkw/findkw/__init__.py ]

# 正则模式查找所有带有 0.1 版本字样的行:
$ findkw -k "[Vv]ersion[\': ]+0\.1\.\d" -r
# in file [ /root/Findkw/setup.py ]: 
# >>> [ 8 ] [ 'version': '0.1.0', ]

# in file [ /root/Findkw/findkw.egg-info/PKG-INFO ]: 
# >>> [ 3 ] [ Version: 0.1.0 ]

# 正则替换行,只保留匹配到的数字,加参数 -qr 是静默更改模式,不会出现提示:
$ findkw -k "VERSION\.(\d+)" -rt "\1" -r -qr
# line [ 19 ]: "VERSION.123" ✘
# replace to
# line [ 19 ]: "123" ✔

2. 在代码中调用:

下载 Finder/findkw/findkw.py 文件到你的代码目录中

from findkw.findkw import Finder

folder = "/root/search_folder"
kw = "正则表达式或者关键字"
fn_only = False     # 如果只返回文件夹或文件夹名则 True
re_mode = False     # 如果kw是正则表达式则 True

fd = Finder(folder, kw, fn_only, re_mode, True)
res = fd.start()

print(res)

Metadata

Release files for findkw 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for findkw 0.3.3
File Size Uploaded
findkw-0.3.3.tar.gz 9.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for findkw 0.3.3
File Interpreter ABI Platform
findkw-0.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 21.3 kB

Release files / findkw-0.3.3.tar.gz

Download URL findkw-0.3.3.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0b59d5d651c397b5c374f08fa5c3ce3cc32345360d4194b9bdc0760d224887e2
BLAKE2b-256 checksum
How to use checksums
8fe331d032cddb9d1a46a28f0483d2b15710c9184fd3a61a17a33efc12194922
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.0

Release files / findkw-0.3.3-py3-none-any.whl

Download URL findkw-0.3.3-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
067e01a183e02c02755d5403d54ea5303fee9a6b476aae18a76fb125238764e7
BLAKE2b-256 checksum
How to use checksums
f956d3982c5c9e7e6fc89b4217bf07dd6b045bebd792fb6b0c72c262dc60f9ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.0

Release history Release notifications | RSS feed

This release

0.3.3 This release

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page