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
219 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
  • 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

733 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