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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:42:49+00:00 2026-05-25T15:42:49+00:00

I have the following script: import os import stat curDir = os.getcwd()+’/test’ for (paths,

  • 0

I have the following script:

import os
import stat

curDir = os.getcwd()+'/test'

for (paths, dirs, files) in os.walk(curDir):
        for f in files:
            if os.stat(f)[stat.ST_SIZE]>0:
                print f

and the folder test/:

test_folder:
    --test.wav
a.exe
t1
t2
rain.wav

when i run this script with geany it gives the following error:

Traceback (most recent call last):
  File "new_folder_deleter.py", line 8, in <module>
   if os.stat(f)[stat.ST_SIZE]>0:
   OSError: [Errno2] No such file or directory: 'a.exe'

but when I run it with IDLE:
it just prints test.wav in subfolder test_folder

Can anyone explain why it is so and how I can fix it?
P.S:
My aim is to browse all files and delete files with specified sizes.

  • 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-25T15:42:50+00:00Added an answer on May 25, 2026 at 3:42 pm

    You need to specify a full path for os.stat, unless the file is in the current working directory. The simplest way to fix this is to change the WD before trying to access the files:

    curDir = os.getcwd()+'/test'
    os.chdir(curDir)
    

    A more general solution is to pass the full path to os.stat:

    if os.stat(os.path.join(paths, f))[stat.ST_SIZE]>0:
      print f
    

    I am not quite sure why IDLE does not produce an error here, though.

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

Sidebar

Related Questions

Hello! I have the following script: import os import stat curDir = os.getcwd() autorun_signature
i have the following script import getopt, sys opts, args = getopt.getopt(sys.argv[1:], h:s) for
I have made the following script to upload a csv and import it into
I have following script: #!/usr/bin/python while True: x = raw_input() print x[::-1] I am
I have the following PyObjC script: from Foundation import NSObject import QTKit error =
I have inherited the following Python script: import urllib2 a = urllib2.urlopen('http://mysite/mypage.aspx?action=dosomething') a.read() a.close()
I have written following script in python which works fine: from sys import argv
I have the following script defining a tzinfo object: import time from datetime import
I have the following simple Python script: import socket import ssl if __name__ ==
I have the following script for importing text files into matlab which include hourly

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.