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
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
217 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

840 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