Wednesday, April 13, 2011

File manipulation - Recursively (including subdirectories)

Some times you may want to manipulate particular file pattern from the current directory and all it's sub-directories. Here, I've demonstrated how to loop through the .txt file then display them using echo then delete it. Likewise, you can manipulate them inside loop.


echo off
rem ********************************************************************
rem * *
rem * Author: Raghunathan K Semburakkiannan *
rem * *
rem ********************************************************************


echo ~~~~~~~~~~~ List of files ~~~~~~~~~~~
echo.
pushd .
for /F "tokens=*" %%i in ('dir /s /b *.txt') do (
echo %%i
del %%i
)
popd
echo.
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
echo.
pause