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 8136471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:46:15+00:00 2026-06-06T10:46:15+00:00

I am trying to delete a files. I check the date and delete if

  • 0

I am trying to delete a files. I check the date and delete if it is older than I want. I noticed that one .zip file was not deleting. It was read only, so in a bit of test code, I used the os.chmod(path, stat.S_IWRITE) and then os.remove(path) and it worked. I put this code into my main code and got the error. I import the os and stat module in both.

Below is the test code that works, but when I put this into the bigger code I got the error and the full code this is just a def as well:

AttributeError: ‘nt.stat_result’ object has no attribute ‘S_IWRITE’

I had checked that the dpath and dayscount are passing the path and number of days.

import os, stat

def del_file(dpath, dayscount):
    if dayscount > 10:
        if dpath[-4:]== ".zip":
            os.chmod(dpath,stat.S_IWRITE)
            os.remove(dpath)
        else:
            os.remove(dpath)
    else:
        print "File is Good"

dpath = "C:\Workspace\Test_Data.zip"
dayscount = 15
del_file(dpath, dayscount)

After reading here I found a link:Code on this page that showed some examples of importing modules. The answer said to import the module in the function. I tried this on my main code and it worked.

The main code imports os and stat at the top of the code, but this function doesn’t seem to see it. And I’m not sure why. When I import it in the module it then sees it. So when put in the main code I had to add the import into the module, see below.

import os, stat

def test_date():
Code for this function

def get_month():
Code for this function

def del_file(dpath, dayscount):
    import os, stat
    print dpath
    print dayscount
    if dayscount > 10:
        if dpath[-4:]== ".zip":
            os.chmod(dpath,stat.S_IWRITE)
            #os.remove(dpath)
        else:
            os.remove(dpath)
    else:
        print "File is Good"

dpath = "C:\Workspace\Test_Data.zip"
dayscount = 13
del_file(dpath, dayscount)
  • 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-06-06T10:46:18+00:00Added an answer on June 6, 2026 at 10:46 am

    You are setting a variable with the name stat somewhere in your code (to the result of an os.stat call). This variable overshadows the stats module.

    Search for stat = and rename the variable to another name, like stat_result.

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

Sidebar

Related Questions

i am trying to delete some files using a batch file.. (winxp) my problem
I am trying to delete part of a string that does not match my
I'm trying to delete files (picture files) in a folder only if they're not
I'm trying to run a batch file through a folder and delete files if
I'm trying to delete some files with unicode characters in them with batch script
I am trying to delete the items/files in a grid view. The files are
I'm trying to create a cron job which will automatically delete .jpg files from
I'm trying to convert bmp files in a folder to jpg, then delete the
I'm trying to delete a file from an FTP server in my shell scrip
I'm trying to delete a Image file in WPF, but WPF locks the file.

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.