MS-DOS: Find files recursively

If you need to print out files recursively in Windows, no need to try to download a special program for this.

Open a command prompt and write the following:

cd "C:\Program Files\Windows Media Player"
dir test*.* /b /s >> C:\temp\TEST_files.txt

This finds files which start with test and outputs them in C:\temp.

Also for finding content of files you can use the following:

findstr /s /i guarantee *.*

The above finds the term “guarantee” in all files in the current directory and subdirectories.

Sample program to use:

@ECHO OFF

set p_file=*.sql
set p_content=insert
set p_path="U:\"

:MENU
echo 1. Path: %p_path% (change)
echo 2. File pattern: %p_file% (change)
echo 3. Contains: %p_content% (change)
echo 4. RUN

:GETINPUT
set /p p_selection=Please enter your choice:
if "%p_selection%"=="1" (goto :enter_dir)
if "%p_selection%"=="2" (goto :enter_file)
if "%p_selection%"=="3" (goto :enter_content)
if "%p_selection%"=="4" (goto :run)

:enter_file
set /p p_file=Please enter a file pattern:
goto GETINPUT
:enter_dir
set /p p_path=Please enter the path:
goto :GETINPUT
:enter_content
set /p p_content=Please enter the string contained:
goto :GETINPUT

:RUN
set p_command=findstr /s /i %p_content% %p_file%

REM use the directive X: in order to navigate to
REM other directory than home

u:
cd %p_path%
echo path: %p_path%

echo %p_command%
cmd /k %p_command%

goto :MENU

Leave a Reply