<commit_before>import time
import sys
import os
import ntpath
from watchdog.observers import Observer  
from watchdog.events import PatternMatchingEventHandler
from win32com.shell import shell, shellcon

class FilecopyHandler(PatternMatchingEventHandler):
    patterns = ['*.hex']
    flashed_files = []
    drive = None

    def on_modified(self, event):
        _, filename = ntpath.split(event.src_path)
        if filename in self.flashed_files:
            return

        print event.src_path, event.event_type
        
        dest = self.drive + '\\' + filename
        shell.SHFileOperation(
            (0, shellcon.FO_COPY, event.src_path, dest, shellcon.FOF_NOCONFIRMATION, None, None)
        )

        if os.path.isfile(dest):
            print 'Success'
            self.flashed_files.append(filename)


if __name__ == '__main__':
    args = sys.argv[1:]
    path = args[0] if args else '.'
    drive = args[1] if len(args) > 1 else 'E:'

    handler=FilecopyHandler()
    handler.drive = drive
    observer = Observer()
    observer.schedule(handler, path=path)
    observer.start()

    print 'Watching folder', path, 'copying to', drive
<commit_msg>Automatically delete flashed files<commit_after>import time
import sys
import os
import ntpath
from watchdog.observers import Observer  
from watchdog.events import PatternMatchingEventHandler
from win32com.shell import shell, shellcon

class FilecopyHandler(PatternMatchingEventHandler):
    patterns = ['*.hex']
    drive = None

    def on_modified(self, event):
        _, filename = ntpath.split(event.src_path)

        print event.src_path, event.event_type
        
        dest = self.drive + '\\' + filename
        shell.SHFileOperation(
            (0, shellcon.FO_COPY, event.src_path, dest, shellcon.FOF_NOCONFIRMATION, None, None)
        )

        if os.path.isfile(dest):
            print 'Success'
            try:
                os.remove(path + '/' + filename)
            except:
                pass


if __name__ == '__main__':
    args = sys.argv[1:]
    path = args[0] if args else '.'
    drive = args[1] if len(args) > 1 else 'E:'

    handler=FilecopyHandler()
    handler.drive = drive
    observer = Observer()
    observer.schedule(handler, path=path)
    observer.start()

    print 'Watching folder', path, 'copying to', drive

{'fraction_non_alphanumeric': 0.10081510081510081, 'fraction_numerical': 0.006006006006006006, 'mean_word_length': 2.6551724137931036, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '475585', 'n_tokens_mistral': 714, 'n_tokens_neox': 694, 'n_words': 179}