How to delete folders/subfolders with files using Batch file

May 13, 2015 at 05:34:28
Specs: Windows 7, Intel/4GB
I have a root folder called "Names"..It has sub-folders ,these sub-folders contains files. I will be giving the names of sub-folders to be deleted in text file Ex..
John
Tom
Rambo.
I will be reading the folder names from text file & delete only those folders with files inside the folder also .

Please provide me the code for it


See More: How to delete folders/subfolders with files using Batch file

Report •


#1
May 13, 2015 at 20:44:31
You want to delete the folders in the list which contain files. And keep them if they are empty. Right?

=====================

M2 Get custom script or take private lessons


Report •

#2
May 14, 2015 at 00:54:31
Hi Mechanix2Go,

I will have folder names in the text file ,I will be reading each folder names & delete folders & files present inside the folder .The root folder will remain as it is.. It should delete only folders whose names are present in the text file

Ex: C:\Temp\RootFolder

Folders present inside the RootFolder should be deleted..Not all folders..only folders whose names are present in the text file


Report •

#3
June 8, 2015 at 18:50:57
This script should be saved as a .bat file in your "RootFolder".
It will delete all folders listed in the file, both empty ones and ones with content.

@Echo off
setlocal enabledelayedexpansion
for /f %%A in (NameList.txt) do (
if exist %%A (
rd /s /q %%A
)
)

Change "NameList.txt" in the script to your folder name list .txt file.

99 little bugs in the code,
99 little bugs.
Take one down, patch it around,
129 little bugs in the code.

message edited by RainBawZ


Report •

Related Solutions


Ask Question