Tech Support banner

Status
Not open for further replies.
1 - 16 of 16 Posts

·
Registered
Joined
·
101 Posts
Discussion Starter #1
Is it possible to check the archive attribute on a file with DOS?
I have a series of directories that need to have their files deleted once the archive attribute has been removed i.e. in Windows Explorer under the Attribute column the 'A' has disappeared.

How would one go about checking. I can gather a list of the file names in the directory. I assume that it would be the command
Code:
If not exist [archive attribute] (
delete file)
However I may be barking up the wrong tree.
Has anyone any experience with this?
 

·
Administrator, Manager, Microsoft Support, Acting
Joined
·
34,380 Posts
Re: Checking archive attribute on file with DOS

Hi Tigers!. . .

Welcome back to the Tech Support Forum!

I like that name "directories" - Good Stuff!

I may be missing something here, but why do you first ned to remove the -A attribute prior to deletion? Or are you trying to delete all files without the -A? If so ... what about -S, -H, etc...?

Regards. . .

jcgriff2
 

·
Registered
Joined
·
101 Posts
Discussion Starter #3
Re: Checking archive attribute on file with DOS

Sorry about that. I managed to be ridiculuosly vague :4-thatsba

The files in question have come across the network to a backup server. They comprise data and sytem files. Before backing up they have their archive and compress attributes set. Once they are backed up the archive attribute is removed but the compress attribute is still there. The data files must be removed as they clog up the system, fill the directories and cause the next day's backup to go slowly or fail.
You would think that the back up program would do this but it does not :)upset:). For a humungous fee the company will rewrite the software to do the removal.
We are hoping it is cheaper and quicker to do it via DOS.

So the need to check that the data file's archive attribute has been reset or removed.
 

·
Administrator, Manager, Microsoft Support, Acting
Joined
·
34,380 Posts
Re: Checking archive attribute on file with DOS

The problem that I see is how to determine if the -A was ever there to begin with.

I don't suppose the bloated-software firm provides any indication, huh?

Regards. . .

jcgriff2

EDIT: How many directories/files are we talking about? And...are they limited to certain directories? What about time stamps?

.
 

·
Registered
Joined
·
37 Posts
Re: Checking archive attribute on file with DOS

Very interesting post. I was reading this originally from Ubuntu and I was really curious about how to go about it and rebooted to XP.

The solution I came up is kinda crude but you can expand on it if you want.

Start -> Run -> CMD
CD go to the folder that you want to process.

To view the attributes of the files type:

Code:
ATTRIB
To list the files that you want to delete (not a folder and the A attribute must not be set):

Code:
DIR /A:-D-A
You need to save this to a file so that you can use it in the for the FOR command, add the /B switch to list in bare format.

Code:
DIR /A:-D-A /B > delete.me
You now need to test your FOR loop by echoing it to the screen.

Code:
FOR /F "tokens=1" %i IN (delete.me) DO ECHO %i
If you are satisfied that the for loop is displaying the right files to delete, rewrite it to:

Code:
FOR /F "tokens=1" %i IN (delete.me) DO DEL %i
Delete the delete.me file to clean up.

This is really crude, but I think it will do the job. Do dir /? and for /? to get help on the commands.

To use the FOR command in a batch program, specify %%variable instead of %variable.
Variable names are case sensitive, so %i is different from %I.
deleteme.bat
Code:
DIR /A:-D-A /B > delete.me
FOR /F "tokens=1" %%i IN (delete.me) DO DEL %%i
I hope that this post helped.

After tinkering with the problem a little more, I came up with a shorter version, one which does not need to output the result to a file first.

Code:
FOR /F "usebackq" %i IN (`dir /a:-d-a /b`) DO @echo %i
Add the extra % if you want to store it in a batch file and replace echo with delete.
 

·
Registered
Joined
·
37 Posts
Re: Checking archive attribute on file with DOS

Windows Explorer under the Attribute column the 'A' has disappeared.
Open Windows Explorer.
On the right pane, right click the headers (Name, Size, Type, etc)
Click Attribute to show the attribute(s) of the files.
 

Attachments

·
Registered
Joined
·
37 Posts
Re: Checking archive attribute on file with DOS

I have no idea on what files are being backed up... Maybe you can add a pre-processing step before the deletion of the files, like clearing up any read only or hidden attributes.

If Tigers! will provide us with more details, then we can surely work out something that will solve the problem.
 

·
Registered
Joined
·
1,335 Posts
Re: Checking archive attribute on file with DOS

I think I will just watch this.
You guys are doing great work.

Mack1
 

·
Registered
Joined
·
101 Posts
Discussion Starter #11
Re: Checking archive attribute on file with DOS

Gents (or ladies as the case may be)
I go to bed and voila, wake up with problem well on the way to being solved. :pray:
I few more details for you all
- These are all SAP files that are being backed up and that I need to remove
- The files arrive every 2nd day
- There are 15 directories in total that are in rotating use i.e. not all directories are in use at any given time, in fact only 2 are in use simultaneously.
- The files arrive from the network with their A & C attributes set.
- Once backed up the A attribute is removed but the C is left. The back-up program does this.
- These are 2 file types (Q20_xxxxx.1_nnnnnnnnn and yyyyy.DATAnn) to consider. See attachments 1 & 2. The attachments show the files after the A attribute has been stripped off
- I have been told that the files will only ever have the attributes A & C
 

Attachments

·
Registered
Joined
·
37 Posts
Re: Checking archive attribute on file with DOS

15 directories means that you need to put the command inside a batch file to save yourself the trouble of typing.

Since the directories are rotated, I would place the same copy of the batch file in each of the directory. This can be done via programming but I'm kinda dumb on that side. Maybe someone can make an interactive script of some sort for your.

Also you mentioned that the files only have the A and C attributes set. (had to check what was the C attribute for, and now I know that its for compressed). The filename does not matter I guess because we are just looking for the A attribute.

deleteme.bat
Code:
FOR /F "usebackq" %%i IN (`dir /a:-d-a /b`) DO @DEL %%i
I think that would work. But for safety purposes, copy a working directory to test it out first. Try to run the batch file and replace the del to maybe move command so that you can examine if the moved files are the actual files that you want to delete. If everything is working, then replace the move command with delete command and place the batch file in each one of the 15 directory.

And you can also make shortcuts to the batch files to your desktop (deleteme01.bat to deleteme15.bat) so you just need to run the deletemenn.bat depending on the schedule without browsing to the actual folder.
 

·
Registered
Joined
·
101 Posts
Discussion Starter #13
Re: Checking archive attribute on file with DOS

Thanks for that mate. It has been extremely helpful.
 

·
Registered
Joined
·
101 Posts
Discussion Starter #14
Re: Checking archive attribute on file with DOS

Nantax
While I have you onboard do you knwo a way to check whether a directory has 0 bytes or 0 files?
When I go through the directory list, an empty dir saves me having to do any work on it.
 

·
Registered
Joined
·
37 Posts
Re: Checking archive attribute on file with DOS

Code:
http://www.computing.net/answers/dos/check-if-dir-is-empty/13443.html
 

·
Administrator, Manager, Microsoft Support, Acting
Joined
·
34,380 Posts
Re: Checking archive attribute on file with DOS

Hi Tigers!

It seems that nantax has solved the issue at hand here. If so, kindly mark the thread "SOLVED" by going to the top of the thread and click on "Thread Tools". Thank you.

@nantax... Thank you so much for the solution that you provided to Tigers! Excellent work. Please jump in anytime... OK?? I appreciate it! Also - please know that I was simply asking questions to items that I was unsure of - no criticism on this end whatsoever.

Kind regards. . .

jcgriff2 (JC)
 
1 - 16 of 16 Posts
Status
Not open for further replies.
Top