views:

26

answers:

2

Hello, I am using Gnuwin32 binaries on a Windows environment.
When I want to find files of a certain type, let's say PDF, I usually run:

find . -iname '*.pdf' -print

This works perfectly on any UNIX system.

find.exe . -iname "*.pdf" -print

But under Windows, having replaced single quotes with double-quotes, it only works when there is no pdf file in the current directory, otherwise the * gets expanded.

Worse: when there is exactly one PDF file in the current directory, it will expand, there will be no syntax error and you will get wrong results.

I have tried escaping the * with a caret, a backslash, a star itself, putting inside double quotes: nothing works for me.

Real example:

Okay, here are all my files:

C:\tmp>find . -type f
./a/1.pdf
./a/2.pdf
./a/aa/1.pdf
./b/1.pdf
./b/bb/1.pdf
./b/bb/2.pdf

Good behaviour, wildcard was not expanded

C:\tmp>find . -iname "*.pdf"
./a/1.pdf
./a/2.pdf
./a/aa/1.pdf
./b/1.pdf
./b/bb/1.pdf
./b/bb/2.pdf

C:\tmp>cd a

Caution, inconsistent behaviour, wildcard was expanded:

C:\tmp\a>find . -iname "*.pdf"
find: paths must precede expression
Usage: find [-H] [-L] [-P] [path...] [expression]

C:tmp\a>cd ..\b

Caution, inconsistent behaviour, wildcard was expanded :

C:\tmp\b>find . -iname "*.pdf"
./1.pdf
./bb/1.pdf

Thank you

A: 

@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.

ghostdog74
Same. When I use `C:\gnuwin32\bin\echo.exe "*.txt"` it outputs `a.txt b.txt`. Maybe it is a cmd.exe setting?
Benoit
give findutils a try.
ghostdog74
yes. With GNU find version 4.2.20, I get the same results.
Benoit
ghostdog74: thee [this message](http://www.mail-archive.com/[email protected]/msg01582.html). What version of Windows are you using?
Benoit
I am using Windows XP SP2
ghostdog74
I have found a solution for my problem, thank you for helping me diagnose it. Actually, it did not come from cmd.exe which never expands a `*` and lets programs do that themselves, but from `find.exe` which behaves differently on recent versions of Windows.
Benoit
A: 

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.
Benoit