Find all lowercase files in a sub directory

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mpking
Posts: 2
Joined: 11 Mar 2015 10:19

Find all lowercase files in a sub directory

#1 Post by mpking » 11 Mar 2015 10:23

Anyone have an example I can use?

I need to search thru a bunch of folders and subfolders, and find any files/folders that have lowercase characters. I don't need to change them, just list them, or return an error code, or both.

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Find all lowercase files in a sub directory

#2 Post by dbenham » 11 Mar 2015 11:16

Simple using FINDSTR with the correct regular expression:

Code: Select all

dir /b /s | findstr "[abcdefghijklmnopqrstuvwxyz][^\\]*$"

You cannot use [a-z] because of the reasons described at Why does findstr not handle case properly (in some circumstances)?

See What are the undocumented features and limitations of the Windows FINDSTR command? for an extensive list of FINDSTR oddities.


Dave Benham

mpking
Posts: 2
Joined: 11 Mar 2015 10:19

Re: Find all lowercase files in a sub directory

#3 Post by mpking » 11 Mar 2015 12:17

Thanks!

That fit nicely, and the undocumented features allowed me to have some error handling.

Code: Select all

dir /b /s %EXTRACT% | findstr "[abcdefghijklmnopqrstuvwxyz][^\\]*$" >> %LOG%\%LOGFILE%
IF %ERRORLEVEL% NEQ 1 (
  ECHO Lower Case File Found
  ECHO Check log at %LOG%\%LOGFILE%
  pause
  GOTO:EOF
)


Yes, the error is slightly backwards, because fail for me is when it finds a match.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Find all lowercase files in a sub directory

#4 Post by Squashman » 11 Mar 2015 12:36

Good to know. I didn't know that the range option didn't work correctly with FINDSTR.

Post Reply