Unable to delete specific files from main foldes , sub folders and folders under subfolders as well using Batch Script
Posted: 29 Jun 2022 23:29
I have a folder name Test. Under that there are two subfolders and under each subfolders two more subfolders are there. The main Test folder has dlls and some of the same dlls are present in each of the sub folders and their sub folder as well. Below is the folder structure:
Question: I need to remove certain dlls from Test folder and it’s subfolder as well. For example I need to delete 1.dll, 2.dll, 3.dll wherever these are present in the Test folder using batch script. In batch script code I provided the option for user to provide the input of the path, so that it can be used by anyone based on folder path. Below is my Batch script code.
However it does not delete the required files. Can someone look in to the code and check if any mistake I made.
Question: I need to remove certain dlls from Test folder and it’s subfolder as well. For example I need to delete 1.dll, 2.dll, 3.dll wherever these are present in the Test folder using batch script. In batch script code I provided the option for user to provide the input of the path, so that it can be used by anyone based on folder path. Below is my Batch script code.
Code: Select all
@echo off
cls
set /p path=Enter destination folder :
set list=ActiveReports.Chart.dll ActiveReports.Document.dll ActiveReports.HtmlExport.dll
set back=%cd%
Rem echo %list%[0]
set count = 0
set notfounddlls=""
REM for %%a in (%list%) do echo(del /s/q %var%\%%a)
for /d /r %%d in (%path%\*) do (
rem set test = %%d
echo --------------------------
rem echo %%d
rem echo --------------------------
pushd %%d
cls
rem for %%i in %list% do (echo %%i)
(for %%a in (%list%) do (
rem echo %%a
IF exist %%a (
set count =1.
del %%a.
Echo %%a deleted
) ELSE (
set count = 0.
ECHO %%a file not found in %%d.
rem set notfounddlls=%notfounddlls%;%%a
rem ECHO Nothing has been deleted from %%d.
rem ECHO.
)
))
cd
cd %back%
)
pause