-3

How to write a batch file called EX5.BAT that lists all files matching any of the following criteria within the Windows folder and down through its sub directories?

  1. Files with an extension starting with letter C.

  2. Files without a file extension.

Mofi
  • 46,139
  • 17
  • 80
  • 143
MsM
  • 1

3 Answers3

2
dir c:\windows\*. c:\windows\*.c /s/b/a-d
Noodles
  • 1,981
  • 1
  • 11
  • 4
  • For me this only lists files with no extensions. None the less +1, I completely forget about `dir`. – Monacraft Aug 18 '14 at 00:26
  • There will be no files in the Windows directory with just a c extension, unless you put one there. Try this command (we'll do System32 to make it shorter) `dir %windir%\system32\*. %windir%\system32\*.txt /a-d/b/s` – Noodles Aug 18 '14 at 00:33
  • ok i try it. its working fine but there a small mistake. so we shold replace (*.C) with (*.C*) cause we want the extention that start with C like (.COM) ,(.conf) and so on. – MsM Aug 18 '14 at 15:19
0

Easy:

Individually

pushd C:\Windows\
:: Part A
for /r %%a in (*.c*) do Echo %%~a
:: Part B
for /r %%a in (*) do if "%%~xa"=="" Echo %%~a
popd

In one for-loop

setlocal enabledelayedexpansion
pushd C:\Windows\
for /r %%a in (*) do (
set var=%%~xa
if "!var!"=="" Echo %%~a 
if "!var:~0,2!"==".c" Echo %%~a
)
popd

The latter method is obviously faster, but I posted the first one in case you wanted to do it individually as it is a lot cleaner.

Community
  • 1
  • 1
Monacraft
  • 6,510
  • 2
  • 17
  • 29
0

I think I fond the Answer:

@echo off
rem a)
for /r c:\Windows %%X IN (*.C*) Do Echo %%X 
pause
rem b)
for /r C:\Windows %%x  IN (*.) Do echo %%x
pause
MsM
  • 1