Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 28th, 2006, 02:56 PM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default possibly C++ snippet of code

I have this piece of code that has been handed to me.

My question is can anyone tell me what language it is written in? Is it Python? or C++?? I think it is something along those lines?

Also, if anyone can quickly tell me roughly what the code is doing that would be EXCELLENT! I dont need a lot of details, i can look into once i know kinda what its doing...... :-/

from __future__ import nested_scopes
import os, time

def watch_directories (paths, func, delay=0.2):

    all_files = {}
    def f (unused, dirname, files):
        for filename in files:
            path = os.path.join(dirname, filename)

                t = os.stat(path)
            except os.error:
                # A file has been deleted between os.path.walk()

            mtime = remaining_files.get(path)
            if mtime:
                # Record this file as having been seen
                del remaining_files[path]
                # File's mtime has been changed since we last looked at it.
                if t.st_mtime > mtime:
                # No recorded modification time, so it must be
                # a brand new file.
            all_files[path] = t.st_mtime

    # Main loop
    rescan = False
    while True: #scan forever
        changed_list = []
        remaining_files = all_files.copy()
        all_files = {}
        for path in paths:
            os.path.walk(path, f, None)
        removed_list = remaining_files.keys()
        if rescan:
            rescan = False
        elif changed_list or removed_list:
            rescan = func(changed_list, removed_list)
            print 'Changed Files', changed_list
            print 'Removed', removed_list

import os
if __name__ == '__main__':
    def f (changed_files, removed_files):
        print 'Changed Files', changed_files
        print 'Removed', removed_files
    while True:
            watch_directories('/home/crmpicco/', f, 1)
            ##watch_directories('.', f, 1)
        except KeyboardInterrupt:
            print "I cant be stopped (unless you try a lot)"
Many Thanks,

Ayrshire Minis - a Mini E-Community
Reply With Quote
  #2 (permalink)  
Old July 1st, 2006, 08:46 PM
Friend of Wrox
Join Date: Jan 2006
Location: San Francisco, CA, USA.
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts

It's python. It monitors a directory looking for files to be changed or deleted. If it finds any changes, it outputs them to the console. The program runs for what looks like forever -- you would likely have to use a system kill command to stop it.

Jon Emerson
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to run code snippet in regular interval Swati Chari Beginning VB 6 2 March 12th, 2008 03:07 PM
Include & Output (possibly) Help MargateFan XSLT 2 June 14th, 2006 05:28 AM
Code snippet to fetch data from other site leo_vinay ASP.NET 1.0 and 1.1 Professional 3 April 3rd, 2006 12:31 PM
Code snippet error on page 370 cebartling BOOK: Professional Java Development with the Spring Framework 0 September 18th, 2005 10:00 PM
Possibly *bug* in book ? A. GRebstad Classic ASP Databases 1 August 7th, 2003 06:27 AM

All times are GMT -4. The time now is 09:21 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.