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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:45:21+00:00 2026-05-23T23:45:21+00:00

I wrote some code to tackle a work-related problem. The idea is that the

  • 0

I wrote some code to tackle a work-related problem. The idea is that the program is in an infinite loop and every 10 minutes it checks a certain folder for new files and if there are any, it copies them to another folder. My code reads all the files in the folder and drops the list into a txt file. After 10 minutes it checks the folder again and compares the old list with a new list. If they are identical, it doesn’t do anything. This is where I stopped, because my idea is iffy and stupid and started to think of better ways. Here’s the code

import time
import os, os.path
i=1
while i==1:    
    folder="folderlocation"
    def getfiles(dirpat):
        filelist = [s for s in os.listdir(dirpat)
             if os.path.isfile(os.path.join(dirpat, s))]
        filelist.sort(key=lambda s: os.path.getmtime(os.path.join(dirpat, s)))
        return filelist
    newlist=getfiles(folder)
    outfile='c://old.txt'      
    last=newlist
    text_file = open(outfile, "r")
    oldlist = text_file.read()
    text_file.close()
    if str(last) == str(oldlist):
        i==i
        print "s"
    else:
        with open(outfile, 'w') as fileHandle:
       #this part is virtually useless
            diff=list(set(lines) - set(last))
            print diff
            fileHandle.write(str(getfiles(folder)))           
    time.sleep(600)

This realization has some bugs in it and doesn’t work as I would like to.
Is there another way of tackling it. Is it possible for it to just remember the latest modified date and after 10 minutes there are files that are newer, then it points them out? Don’t need the copying part just yet but really need the checking part. Does anyone have some ideas or some similar code?

  • 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-23T23:45:23+00:00Added an answer on May 23, 2026 at 11:45 pm

    The cleanest solution is file alteration monitoring. See this question for information for both *ix and Windows. To summarize, on Linux, you could use libfam, and Windows has FindFirstChangeNotification and related functions.

    There are some clear problems with your script, such as NOP lines like i==i. You also don’t need to convert to a string before comparing.

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

Sidebar

Related Questions

I wrote some code with a lot of recursion, that takes quite a bit
I recently wrote some javascript code that filled a drop down list based on
I am testing some weird-looking CSS code that I wrote (I'm using a mix
I wrote some code that mute the phone whenever an incoming call is received.
I wrote some code that has a jpanel with a mouse listener and mouse
I wrote some code that stores on the disk some RTP packets with H264
I wrote some code that works well on chrome. However, when running it on
I wrote some code in C for a TCP Server that echoes whatever it
I wrote some code to ensure that my database will be updated properly when
I wrote some html/css/javascript code that was taken verbatim from a javascript textbook. For

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.