Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7417769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:45:43+00:00 2026-05-29T07:45:43+00:00

I have put together a script to delete backed up files, but believe I

  • 0

I have put together a script to delete backed up files, but believe I am have the archive bit attribute confused.

$path = "D:\logs\"
$files = Get-ChildItem -Path $path -Recurse
$attribute = [io.fileattributes]::archive   #archive bit
$date = get-date -format d     # strip time out of date, date needed for Filename
$date = $date.replace('/','.') # strip out forward slashes and replac with . in date
$filename = "\ArchiveLog"+$date+".txt" # Filename for log file.
$location = $path+$filename 
cd D:\logs 

Foreach($file in $files)
{
 If((Get-ItemProperty -Path $file.fullname).attributes -band $attribute)
  { 
    add-content -path "$path" "$file.DirectoryName has been deleted"
    Remove-Item $file -force
  }
}

however when I test this, this script deletes brand new files that have just been created, as the files that are newly created have the “A” attribute or archive bit.

When I have looked at other sample scripts they usually have the line, that ensures the files archive bit is set:

attribute = [io.fileattributes]::archive   #archive bit
If((Get-ItemProperty -Path $file.fullname).attributes -band $attribute)
{ 
log file name    
Remove file
}

So … I was wondering if this is something new to windows 2008 r2 where the archive bit “A” is set automatically upon creation, or if perhaps the other scripts I have found are wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:45:44+00:00Added an answer on May 29, 2026 at 7:45 am

    I think you are making this more complicated than it needs to be. Here’s an example where I return only TXT files with the ARCHIVE attribute set:

    PS C:> dir c:\work*.txt | where {$_.attributes -match “Archive”} | select name
    ,attributes

    You can add additional filtering as needed if you only want files newer or older than a certain date.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have put together a script which is very much like the flickr photostream
I have put together the following mootools script window.addEvent('domready', function() { var shouts =
I have put together this little script which uses a list of words to
I have put together some code from various sources but javascript is somewhat unknown
I have put together a script which will upload a CSV file and then
I have a scenario where I need to put together a script to add
I have a php script that I've put together from examples on the internet.
Greetings: I have put together a RESTful web service in .NET 3.5 that takes
I am a powershell novice. After days of searching.... I have put together a
Hello I have problem to put together animations of two separate objects to second

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.