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
210 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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

708 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

12 Experts available now in Live!

Get 1:1 Help Now