Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello
I am trying to write a simple script that will del /s all *.mp3 files from within a directory but exclude a single folder from having its *.mp3 deleted.
How can I exclude this directory.
Thank you
Steve

Hi Alexanrs
Not really because the I am going to be using the script against 1000's users home drives to delete media type files. The folder that I am trying to exclude is to be a safe folder that we won't delete media files from.
Thank you
Steve

Depends on the version of DOS.
=====================================
If at first you don't succeed, you're about average.M2

I think DEL doesn't delete files if they are flagged as read-only, so you can set the attribute in the beggining of the script and then reset it in the end, like:
----------- Beggining --------------
@ECHO OFF
:: This example suposes your first parameter is
:: the relative path to the folder to be deleted
:: and the second is the relative path (from the
:: the target folder) of the one to be excluded
:: Notice that this will only work if the folders
:: are in the working drive, if not, you'll
:: have to specify full pathsIF NOT EXIST %1\NUL GOTO ERROR
CD %1
IF NOT EXIST %2\NUL GOTO ERROR
ECHO Starting up the deletion process
ECHO. * Setting attributes
attrib %1\*.mp3 -r -s -h > NUL
attrib %2\*.mp3 +r > NUL
ECHO. * Deleting files
del /s %1\*.mp3
ECHO. * Reseting attributes
attrib %2\*.mp3 -r > NUL
ECHO.
ECHO Operation completed!
ECHO.
GOTO END:ERROR
ECHO Parameters:
ECHO. Param1 -> target folder
ECHO. Param2 -> folder to be ignored
ECHO.
GOTO END:END
-------By the way, you are either using XP (since MS-DOS' command.com do not suport del/s) or your clients are using something like 4DOS or some other enhanced shell)

I seem to recall the ATTRIB command can also be used with folders/directories.
However expanding on Mechanix' advice, some commands function differently depending on the version of dos it came with.
Good Luck - Keep us posted.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |