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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:28:48+00:00 2026-06-09T17:28:48+00:00

I have a Python script which looks for any changes in a folder(addition/deletion) of

  • 0

I have a Python script which looks for any changes in a folder(addition/deletion) of files.
I am looking for any new files added and wants to open them and read some data from them.

The code is

# Utility to check for any new jobs

import os
import win32file
import win32event
import win32con
import string

path= r"C:\Users\dZONE\Desktop\py"

change_handle = win32file.FindFirstChangeNotification      (path,0,win32con.FILE_NOTIFY_CHANGE_FILE_NAME)

try:

  old_path_contents = dict ([(f, None) for f in os.listdir (path)])
while 1:
  result = win32event.WaitForSingleObject (change_handle, 500)


if result == win32con.WAIT_OBJECT_0:
  new_path_contents = dict ([(f, None) for f in os.listdir (path)])
  added = [f for f in new_path_contents if not f in old_path_contents]
  #deleted = [f for f in old_path_contents if not f in new_path_contents]
  if added: print "Added: ", ", ".join (added)
  #if deleted: print "Deleted: ", ", ".join (deleted)
  # My open
  print "Len" , len(added)
  for item in added:
   print item
   ad=open(item,'r')
   print ad.read()

  old_path_contents = new_path_contents
  win32file.FindNextChangeNotification (change_handle)

 finally:
   win32file.FindCloseChangeNotification (change_handle)

When i am trying to open the file it is giving me the IO Error 13. Though i have rights on the folder and the file. I wrote another test code and tried opening the same file directly giving the file name to open() and it did worked.

If anyone can point out the mistake i am doing would be really appreciated.

EDIT: Error message

Traceback (most recent call last):
File "C:\Users\dZONE\Desktop\py\util.py", line 50, in <module>
ad=open(item,'r')
IOError: [Errno 13] Permission denied: 'ad.sjs_hdr'

P.S I am new to python so maybe i am making some really silly mistake
thanks

  • 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-09T17:28:50+00:00Added an answer on June 9, 2026 at 5:28 pm

    The .listdir() method gives you filenames without paths only, you are probably trying to open a file in the current directory, not in the directory named by path.

    You have to use the os.path.join function to put path and item together:

    for item in added:
        print item
        fullfilename = os.path.join(path, item)
        ad=open(fullfilename,'r')
        print ad.read()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a python script which watches a directory for new subdirectories, and
I have a python script that runs a program, which generates few .exe files
I am writing a python script which looks at common computer files and examines
I have a python script which looks like: if options.benchmark == 'perlbench': process =
I have python script which downloads N number of images from website. I run
I have a python script which outputs lots of data, sample is as below.
i have a python script which keeps crashing on: subprocess.call([pdftotext, pdf_filename]) the error being:
I have a small python script which draws some turtle graphics. When my script
I have the following python script which takes some inputs and puts them in
In my Python script which uses Curses, I have a subwin to which some

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.