Author Topic: Batch Script - Search and Delete - Need Help adding on to it  (Read 13708 times)

0 Members and 1 Guest are viewing this topic.

Offline sryker1911

  • /dev/null
  • *
  • Posts: 7
  • Cookies: 0
    • View Profile
Batch Script - Search and Delete - Need Help adding on to it
« on: February 27, 2013, 02:31:47 am »
Need some help coding this in BAT.

The script is written so that it does a recursive search with WMI to delete specific files on the the fixed drives.

I would like to know how to make it so that it has logic like the following, I just can't seem to figure this out in this script

IF folder above "fileName0.url" == blue  && AND && fileName == fileName0.url

Then Delete file fileName0.url

else if - ignore


What I has so far, anyone have any ideas or have code to add to make it perform like the logic above
Code: [Select]
@echo off
Title Search and Delete Specific File
::Find out what disks are on the system.
for /f "usebackq skip=1 tokens=1" %%a in (`wmic logicaldisk get deviceid`) do (
   ::Make sure we only use the fixed disks
   for /f "usebackq tokens=2 delims=:- " %%x in (`fsutil fsinfo drivetype %%a`) do (
      ::Is %%a, a fixed disk?
      if "%%x" == "Fixed" (
         echo.
         echo - - - - - - - - - - - - - - - - - - - - - - - - -
         echo Searching drive %%a for Startup Shortcuts
                 del /s/f/q "%%a\fileName0.url"
              del /s/f/q "%%a\fileName1.url"
         )
      )
   )
)
« Last Edit: February 27, 2013, 02:35:39 am by sryker1911 »

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: Batch Script - Search and Delete - Need Help adding on to it
« Reply #1 on: February 27, 2013, 06:44:47 am »
Look here how to get the parent directory name: http://stackoverflow.com/questions/2396003/get-parent-directory-name-for-a-particular-file-using-dos-batch-scripting

For the rest you just create an if statement with the AND operator to concatenate your conditions.
http://www.robvanderwoude.com/battech_booleanlogic.php

Offline sryker1911

  • /dev/null
  • *
  • Posts: 7
  • Cookies: 0
    • View Profile
Re: Batch Script - Search and Delete - Need Help adding on to it
« Reply #2 on: March 02, 2013, 09:30:26 pm »
Thanks I got it working!  :)