<http://www.netikka.net/tsneti/info/tscmd159.htm>
Copyright © 2003-2010 by Prof. Timo Salmi  
Last modified Sat 8-May-2010 17:07:11

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip command line interface (CLI) collection. That zipped file has much additional material, including a number of detached .cmd script files. It is recommended that you also get the zipped version as a companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.



159} How do I test that a name does not contain lowercase letters?

Let's limit the lowercase letters to the English alphabet a-z only.
  @echo off & setlocal enableextensions
  set name_=%~1
  if "%name_%"=="" (
    echo Usage: [NameToBeChecked]
    goto :EOF
    )
  ::
  echo %name_%|findstr "[abcdefghijklmnopqrstuvwxyz]">nul
  if %errorlevel% EQU 0 (
    echo The name "%name_%" is not uppercase only
    ) else (
    echo The name "%name_%" is uppercase only)
  endlocal & goto :EOF

Examples of the output
  C:\_D\TEST>cmdfaq "My Test File.txt"
  The name "My Test File.txt" is not uppercase only

  C:\_D\TEST>cmdfaq "MY TEST"
  The name "MY TEST" is uppercase only

There is a catch in using findstr regular expressions. In the above FINDSTR "[a-z]" would not work as expected from the common regular expressions definitions. The set option [a-z] seems to case insensitive in the XP command line interface!

The central line of the task could be written in a "one-liner" style as follows
  @echo off & setlocal enableextensions
  set name_=%~1
  if "%name_%"=="" (
    echo Usage: [NameToBeChecked]
    goto :EOF)
  ::
  echo %name_%|findstr "[abcdefghijklmnopqrstuvwxyz]">nul&&echo Not upcase||echo Upcase
  endlocal & goto :EOF

Examples of the output
  C:\_D\TEST>cmdfaq "My Test File.txt"
  Not upcase

  C:\_D\TEST>cmdfaq "MY TEST"
  Upcase

Run the command following && only if the command preceding the symbol is successful.
Run the command following || only if the command preceding || fails.

What if we wish to list the UPPERCASE-only files in a folder?
  @echo off & setlocal enableextensions
  if "%~1"=="" (
    echo Usage: "%~f0" "FolderName"
    goto :EOF)
  if not exist "%~1\" (
    echo Folder "%~1" not found ^(or is a file^)
    goto :EOF)
  pushd "%~1\"
  for /f "tokens=*" %%f in ('
    dir /a:-d /b^|findstr /v "[abcdefghijklmnopqrstuvwxyz]"') do (
      call :DisplayDateSizeName "%%~ff")
  popd
  endlocal & goto :EOF
  ::
  :DisplayDateSizeName
  set filename_="%~f1"
  set filesize_=          %~z1
  set filesize_=%filesize_:~-10%
  echo %~t1 %filesize_% "%~1"
  goto :EOF

Part of the output could be e.g.
06.06.1998 06:18        334 "TESTADD.BAT"
04.06.1998 09:31        146 "TESTFNGT.BAS"
07.11.2001 08:19       1462 "TIEDEKN.BAT"
12.06.2008 01:24        594 "VBSFAQ.VBS"
06.10.2007 08:28       4084 "VBSFAQ2.VBS"

References/Comments:
  hh ntcmds.chm::/ntcmds_shelloverview.htm
  hh ntcmds.chm::/findstr.htm