Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 28th, 2006, 02:56 PM
Friend of Wrox
Join Date: Jan 2005
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
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

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

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