Lately i have been making this batch file and it is driving me nuts.
My Folder Structure is like C:\MainFolder\Dir\ and "Dir" contains many sub Folders and Files. Within these Sub Folders there are many files and sub Folders including 2 files "C.txt" and "D.txt" My Task is to delete everything else in these sub folders and only keep these 2 files. But it is not working. Please Help.
My Code is :
@echo off
FOR /f "tokens=*" %%M in ('dir /b "C:\MainFolder\Dir\"') DO (
For /f "tokens=*" %%S in ('dir /b "C:\MainFolder\Dir\%%M"') DO (
if "%%S"=="C.txt" (
echo Found C
)
else if "%%S"=="D.txt" (
echo Found D
)
else (
::Code to delete the file Or Directory
echo Deleted %%S
)
)
)
echo Deleted Unwanted Content
pause