Gnuwin32 find.exe 在执行搜索之前扩展通配符

发布于 2024-09-28 11:00:33 字数 1549 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

衣神在巴黎 2024-10-05 11:00:34

我没有找到比避免通配符更好的东西

find.exe . -iregex ".+\.pdf" -print

I haven't found anything better than just avoiding wildcard characters

find.exe . -iregex ".+\.pdf" -print
枯寂 2024-10-05 11:00:34

@OP,我有一致的行为

C:\test\temp>find . -iname "*.txt"
./1.txt
./2.txt

C:\test\temp>cd a

C:\test\temp\a>find . -iname "*.txt"

C:\test\temp\a>cd ..\b

C:\test\temp\b>find . -iname "*.txt"

C:\test\temp\b>find --version
GNU find version 4.2.20
Features enabled: CACHE_IDS D_TYPE

您可能想尝试使用 findutils 而不是 UnxUtils。

@OP, i have consistent behaviour

C:\test\temp>find . -iname "*.txt"
./1.txt
./2.txt

C:\test\temp>cd a

C:\test\temp\a>find . -iname "*.txt"

C:\test\temp\a>cd ..\b

C:\test\temp\b>find . -iname "*.txt"

C:\test\temp\b>find --version
GNU find version 4.2.20
Features enabled: CACHE_IDS D_TYPE

You may want to try to use findutils instead of UnxUtils.

反话 2024-10-05 11:00:33

我已经找到了解决问题的方法。

  • Gnuwin32 的 find.exe 不适用于最新的 Windows 版本(Vista、7),因为它扩展了仅匹配当前目录内容的通配符。
  • 同样,UnxUtils 的旧版本 find.exe 也遇到了同样的错误。
  • UnxUtils 的最新 find.exe 正在运行。

I have found myself the solution to my problem.

  • Gnuwin32's find.exe is not working on recent Windows Versions (Vista, Seven) because it expands wildcards matching only the contents of the current directory.
  • Similarly, an old version of find.exe from UnxUtils suffered the same bug.
  • The latest find.exe from UnxUtils is working.
最初的梦 2024-10-05 11:00:33

一种解决方法是添加 Windows shell 不会扩展的通配符/扩展,但 GNU find 会扩展:

find.exe . -name *[.:]pdf -print

Windows shell[*] 不会解释/扩展方括号。此外,冒号在 Windows 文件名中不是有效字符,因此此模式无法匹配任何 Windows 文件名,并且 Windows shell 始终会将该模式传递给 find.exe。

然后,Find.exe 将查找以 .pdf:pdf 结尾的任何文件,但由于文件名不能以 :pdf 结尾Windows,它只会查找以 .pdf 结尾的文件。

[*] 实际上是 C 运行时执行/不执行这些通配符扩展。我对 Win32 C 运行时的了解还不够深入,无法细化这种区别,所以现在为了解决这个问题,我只是说“shell”。

One workaround is to add a wildcard/expansion that the Windows shell does not expand, but GNU find does:

find.exe . -name *[.:]pdf -print

The Windows shell[*] does not interpret/expand square braces. In addition, colon is not a valid character in Windows filenames, so this pattern cannot match any Windows filename, and the Windows shell will always pass the pattern through to find.exe.

Find.exe will then find any files ending in .pdf or :pdf , but since no files can have a name ending in :pdf under Windows, it will only find files ending in .pdf.

[*] It's actually the C runtime that does/not perform these wildcard expansions. I don't understand the Win32 C runtime well enough to refine the distinction, so for now for the purpose of this workaround, I'm just saying 'shell'.

清醇 2024-10-05 11:00:33

今天下午我就遇到了这个问题。
Benoit 的 UnxUtils 可以工作。
我还发现MinGW的find.exe可以工作,它在我的下面

“MinGW\msys\1.0\bin”

目录。而且和说明书是一致的。

gnuwin32 和 UnxUtils:find.exe 。 -name GameCli* 可以工作,但是
find.exe 。 -name 'GameCli*' 不起作用。

MinGW 的 find.exe 。 -name 'GameCli*' 工作。

I suffered this problem this afternoon.
Benoit's UnxUtils can work.
I also find MinGW's find.exe can work,it is under my

"MinGW\msys\1.0\bin"

directory. And it is consistent with the manual.

gnuwin32 and UnxUtils: find.exe . -name GameCli* work, but
find.exe . -name 'GameCli*' doesn't work.

MinGW's find.exe . -name 'GameCli*' work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文