Answer the question
In order to leave comments, you need to log in
How to create a Bat-ik that would delete folders with a few exceptions?
Hello, there was a problem with creating a script that should recursively delete folders along the path C:\Users\Desktop\Bat\Test, while not touching 3 folders and 2 files. Can't make an exception for more than 1 folder.
Please help and if possible, describe what the actions mean. I 've been fiddling with this all day :(
Here's what I could write
@echo off
setlocal enableextensions enabledelayedexpansion
:: Дирректория
set Folder=C:\Users\vasma\Desktop\Bat\Test
:: Поддиректория (или файл), которая НЕ должна удаляться
set NotDeleted="conf" "log" "dumps"
for /f "tokens=*" %%i in ('dir "%Folder%" /b /a:d') do (
set /a bDelete = 1
for %%j in (%NotDeleted%) do (
if /i "%%i" equ "%%~j" set /a bDelete = 0
)
if !bDelete! equ 1 rd /s /q "%Folder%\%%i"
)
endlocal
exit /b 0
Answer the question
In order to leave comments, you need to log in
The script is working, it deletes folders and their contents, except for the specified one, but does not automatically delete files located in the root folder!
My problem was in the wrong spelling of my folders in the script.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question