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
214 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
3 Use Cases for Connected Systems

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

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to delete empty sub dirs but not include the directory itself 10 68
help with PowerShell script for registry permissions 8 51
xcopy loop 13 42
batch file problem 5 22
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now