Computing.Net > Forums > Disk Operating System > Excluding Folders when using del /s

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Excluding Folders when using del /s

Reply to Message Icon

Name: Mad-Penguin
Date: October 4, 2007 at 04:18:55 Pacific
OS: Windows XP
CPU/Ram: Intel
Product: HP
Comment:

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




Sponsored Link
Ads by Google

Response Number 1
Name: alexanrs
Date: October 4, 2007 at 07:37:22 Pacific
Reply:

Can't you move that folder out of that directory before the del/s command, and then move it back?


0

Response Number 2
Name: Mad-Penguin
Date: October 4, 2007 at 07:45:55 Pacific
Reply:

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


0

Response Number 3
Name: Mechanix2Go
Date: October 4, 2007 at 20:03:51 Pacific
Reply:

Depends on the version of DOS.


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 4
Name: alexanrs
Date: October 5, 2007 at 20:32:39 Pacific
Reply:

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 paths

IF 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)



0

Response Number 5
Name: Mike Newcomb
Date: October 6, 2007 at 02:27:22 Pacific
Reply:

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.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Excluding Folders when using del /s

invalid directory when using cd command www.computing.net/answers/dos/invalid-directory-when-using-cd-command/7470.html

Help! I formatted my hard disc and now I can't get access to my cd-rom drive in order to re-setup windows 95! www.computing.net/answers/dos/help-i-formatted-my-hard-disc-and-now-i-cant-get-access-to-my-cdrom-drive-in-order-to-resetup-windows-95/1903.html

Format DOS Partion after FDISK www.computing.net/answers/dos/format-dos-partion-after-fdisk/15515.html