Solved

How do I delete files that DO NOT have the "A" (archive) attribute set via a batch/script?

Posted on 2007-03-26
7
220 Views
Last Modified: 2010-04-16
This should be pretty easy (or so I think).  How can I (via a batch file) delete all files that do NOT have the A (archive) attribute set (including subdirectories)?

Long story short, once our backup files are shipped to tape, the A attribute is cleared by the backup software.  However these (really big) files are not removed.  I want to run a script each night that cleans up files that have already been shipped (and thus do NOT have the A attribute set).

Thanks!
Dominic
0
Comment
Question by:corpkid
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18794237
Build your list with this command...

dir *.* /s /a-a >> C:\Deletionlist.txt

Then perform the delete using

for /f %%a in (C:\DeletionList.txt) do erase %%a
0
 

Author Comment

by:corpkid
ID: 18794578
Hey Sirbounty - thanks for the help.  That got me close, but the output file (deletionlist.txt) is formated like such:

03/18/2007  11:08 PM             7,644       DATA_BACKUP4_log_200703182100.txt

As such, the 2nd part of the script barks the following errors:

c:\erase 03/18/2007
Invalid switch - "18"

I don't know how to change the output...

Thanks again! :)

Dominic
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 125 total points
ID: 18794707
Why don't we just change the whole thing to this... : )
Remove the 'echo' (and pause) from the line below if it's displaying the files you want to remove...

@echo off
setlocal enabledelayedexpansion
for /r c:\testing %%a in (*.txt) do call :process %%~aa %%~dpnxsa
goto :eof

:process
set strA=%1
set strFile=%2
if /i %strA:~2,1%==a goto :eof
echo del %strFile%
pause
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 30

Expert Comment

by:SteveGTR
ID: 18794778
I'd recommend using Sirbounty's suggest with the inclusion of the /b dir switch:

dir *.* /b /s /a-a > C:\Deletionlist.txt

for /f %%a in (C:\DeletionList.txt) do erase "%%a"
0
 

Author Comment

by:corpkid
ID: 18794797
You are a genius! :)

That worked great!  THANK YOU!
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18794818
That's true - Steve's (the REAL genius) verion might be a better, and less code, method...
Glad it worked for you though.
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18794830
Sirbounty's idea and he came up with the solution. Great work :)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question