How do I write a batch file to delete everything excluding things?
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$2 Answers
::
:: Deletes Directory Entries *Except* for Specified File(s)
:: Wildcards (* and ?) may be Used in the File Name
:: (Hidden, System, and Read-Only Files are Not Affected)
::
@ECHO OFF
MD SAVE Makes a Temporary "SAVE" Directory.
XCOPY %1 SAVE > NUL "> NUL" Suppresses On-Screen Messages.
ECHO Y | DEL . > NUL Deletes all Files in the Current
Directory showing no Prompts.
MOVE SAVE\*.* . > NUL Returns Excepted File(s) to the
RD SAVE Current Directory.
Removes "SAVE" Directory.
ECHO. Adds a Blank Line to the Display.
C:\BATCH\DR Displays the Results of the Operation.
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$the run a DOS command "delete *.del" or something like that.
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$
the only part i don't like about this script is that it doesn't take into account the possibility of subdirectories and the possible need to also delete these or the files in them.
OK: Time to be direct. I wan to delete all user folders inside documents and settings except "All Users", "Administrator", "Default User", and selected others.
The above should delete everything in the directory except for the Hidden, System, and Read-Only Files.
I may be mistaken though, question......what are you using this for....it seems like it might be used for some.....cruel idea.
> OK: Time to be direct. I wan to delete all user folders
> inside documents and settings except "All Users",
> "Administrator", "Default User", and selected others.
Here is an alternate script.
# Script deletusers.txt
# Change directory to Documents and Settings.
cd "C:/Documents and Settings"
# Collect a list of all subfolders.
var str list
lf -n "*" "C:/Documents and Settings" ($ftype=="d") > $list
# Process subfolders one by one.
while ($list <> "")
do
# Get the next subfolder.
var str dir ; lex "1" $list > $dir
# Does this folder name contain "All Users",
# "Administrator" or "Default User" ?
if ( ( {sen "^All Users^" $dir} <= 0 ) AND ( {sen "^Administrator^" $dir} <= 0 ) AND ( {sen "^Default User^" $dir} <= 0 ) ) # This entire if statement must appear on one line.
do
# No this is not a user from our list.
# Delete this folder.
script "SS_SlashBack.txt" ospath($dir) > $dir
system -s "rmdir /SQ" ("\""+$folder+"\"")
done
endif
done
I have not tested the script. Test it first.
The script is in biterscripting ( http://www.biterscripting.com ). To try, save the script as C:/Scripts/deleteusers.txt, enter the following command in biterscripting.
script "C:/Scripts/deleteusers.txt"
I can see a use for such a script - an employee leaves company, you want to delete his/her "stuff" from all company computers.
Patrick