-3

Write a batch program called EX4.BAT which lists all files matching any of the following criteria within the root of the C: drive and down through its subdirectories:

a) Files with an extension of .COM and have 4 letters in the filename. e.g. chcp.com, mode.com etc.

b) .EXE files whose 2nd letter is I e.g., WINHELP.EXE DIAGS.EXE etc.

Make sure the output does not scroll up the screen too quickly. Put a pause command in between parts a) and b)

I tried the following :

cd\ Rem  to return to the root folder of C
dir ????.com /b/s Rem  COM files with 4 letters
pause Rem to pause the screen
dir ?I*.exe /s Rem  search EXE files whose 2nd letter is I 

For part a), doing this like that accept also numbers, I have to make sure that it accepts only letters. I tried to make use of regular expression but in vain.

Compo
  • 36,585
  • 5
  • 27
  • 39
  • 2
    Side note: You cannot put `rem` on the same line like that. You can do `& rem` or use some of the other tricks [explained here](https://stackoverflow.com/questions/12407800/which-comment-style-should-i-use-in-batch-files) like `%= my comment =%`. – CherryDT Jul 12 '20 at 11:19
  • 1
    Hint1: the wildcard `?` means "zero or one character", so `x.com` would be listed too. Hint2: `dir` can't distinguish between letters and numbers. You'd need to filter the output (see `findstr /?`) Hint3: see `dir /?` and note the `/p` parameter. – Stephan Jul 12 '20 at 11:24
  • 1
    _Make sure the output does not scroll up the screen too quickly._ Try https://ss64.com/nt/more.html, something like `dir ?I*.exe /s | more` – JosefZ Jul 12 '20 at 11:38
  • 2
    @JosefZ: `dir /p` does the same. – Stephan Jul 12 '20 at 12:03
  • 1
    I would suggest, where your question states "4 letters in the filename", it means characters, not specifically alphabetic only characters! – Compo Jul 12 '20 at 14:34
  • Do you want a listing with only the filenames or the whole path? Should it also include hidden and system files or only normal files? – Ricardo Bohner Jul 12 '20 at 20:54

1 Answers1

0

Here is a basic example of one method of performing the task laid out in your question, and without the clarification requested in the comment area.

@Echo Off
Setlocal EnableExtensions
Set "PATHEXT="
(   "%__APPDIR__%where.exe" /R C:\ ????.com |^
     "%__APPDIR__%findstr.exe" /E /I /R "\\[a-Z]*\.com"
    Echo(
    Echo Press any key to continue . . .
    Pause 1> NUL
    "%__APPDIR__%where.exe" /R C:\ ?I*.exe
) 2> NUL | "%__APPDIR__%more.com"
EndLocal
Pause

As this is clearly 'homework' I will not be providing any explanation of the commands I have used, or why I have done so, I will also not be adjusting my code to cater for later additions or changes in the task. It is also important to remember, that as this is technically somebody else's submission, you must not present it unless you fully understand how and why it works.

Compo
  • 36,585
  • 5
  • 27
  • 39