Question:
I need help writing a Batch file script for work;?
David
2013-05-06 14:26:35 UTC
I work at a cell phone retail store, and to keep our customer's information safe, corporate offices just issued the stores a .bat file to go through and erase any information on computers, or at least most of it, that could potentially have customer information on it.

Right now, the script is as follows;
C:
cd\
Echo Now Deleting Scrap Drive C ,HomeA Location !!!
del *.jpg /s /a
del *.jpeg /s /a
del *.pdf /s /a
del *.bbb /s /a
del *.ipd /s /a
del *.VCF /s /a
del *.mp4 /s /a
Echo Completing Home A Cleanup 100%

The problem is this; on some computers, we have .jpg images and .pdf images that we need to keep. What I am trying to figure out how to do is code the script to ignore a specific folder on the computer, and delete the rest. I have a minor, minor background in Java, so I'm thinking something along the lines of

if (file is located in C:\Users\Employee\Desktop)
dont delete
else
Mission Impossible status self-distruct.

Any ideas of how I could get this to work for my code? Thanks!
Three answers:
Jake
2013-05-09 08:43:57 UTC
This should do what you're asking. Batch is a hobby of mine so if it doesn't work, or you'd like a menu or something changed, let me know by PMing me.





echo off

cls

echo Deleting Scrap Drive C, Home A Location . . .



Set filetype=*.jpg & call :DeleteProcess

Set filetype=*.jpeg & call :DeleteProcess

Set filetype=*.pdf & call :DeleteProcess

Set filetype=*.bbb & call :DeleteProcess

Set filetype=*.ipd & call :DeleteProcess

Set filetype=*.vcf & call :DeleteProcess

Set filetype=*.mp4 & call :DeleteProcess

Echo Completing Home A Cleanup 100%%

Pause

exit



:DeleteProcess

for /f "tokens=*" %%a in ('dir /b /s "C:\%filetype%"') do (

if not "%%~dpa"=="%userprofile%\Desktop\Example Folder\" del "%%a"

)
?
2013-05-06 22:16:48 UTC
The batch file is a silly "solution". Place each customer's data in a folder renamed with the customer's name. When you're done with that customer's phone, right-click the folder , click Delete while pressing Shift, and click Yes.



It is possible to write a batch file that does a mass deletion while bypassing specified folders. If the above method isn't satisfactory (although I can't imagine why), just say so
anderoo1992
2013-05-06 21:30:37 UTC
It would be much easier to just relocate the files temporarily. It's far easier to include a folder rather than remove one. Save yourself the time and trouble.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...