■
シロさんがフォルダの監視でお悩みのようなので,CraftLaunchExのoutputにディレクトリの変更を表示する方法を具体的に.ちょっと長いけどこんな感じ.これをconfig.pyに貼り付ければいけるはず.
import Queue import threading import win32file import win32api import win32con import os def watch(path): hDir = win32file.CreateFile ( path, 0x0001, win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE, None, win32con.OPEN_EXISTING, win32con.FILE_FLAG_BACKUP_SEMANTICS, None) while 1: result = win32file.ReadDirectoryChangesW(hDir, 1024, True, win32con.FILE_NOTIFY_CHANGE_DIR_NAME, None, None ) yield (path, result) class Watcher (threading.Thread): def __init__ (self, path, result, **keyword): threading.Thread.__init__ (self, **keyword) self.setDaemon (1) self.path = path self.result = result self.start () def run (self): for results in watch(self.path): self.result.put(results) def watch_dir(): try: path_base, results = files_changed.get_nowait () n = len(results) if n == 1: action, path = results[0] path = os.path.join(path_base, path) if action == 1: print "add:", path elif action == 2: print "remove:", path elif n == 2: action1, path1 = results[0] action2, path2 = results[1] path1 = os.path.join(path_base, path1) path2 = os.path.join(path_base, path2) if action1 == 4 and action2 == 5: print 'rename:from %s to %s' %(path1, path2) except Queue.Empty: pass files_changed = Queue.Queue () watch_path = ['c:/', 'd:/', 'g:/'] for path in watch_path: Watcher (path, files_changed) AddTimerHandler(1000, watch_dir)
これをちょこっと応用すれば,clmode_goで使えるんだけど,1つだけ問題が.
それは,削除とリネームもとのファイルが,ショートファイルネームでしか取得できない(少なくとも俺の力量では)ということ.つまり,長いファイルはいったいどのファイルが削除されたのかがわからない.ショートネームから,ロングネームに変換しようとしても元のファイルがないから出来ない.方法としては,削除されたディレクトリの親ディレクトリはわかるので,そのディレクトリから削除されたディレクトリを調べるというのがある.これでがんばれば何とかなるんだけど,めんどいので途中でほったらかしたまま.