0

我测试了这个程序,如果文件被删除、重命名或修改,它会检查目录。我想知道如何通过排除某些文件来检查目录?如何修改变量 PATH_TO_WATCH = ["C:/myDirectory"],以便程序探测C:/myDirectory但不检查 2 个文件(file1.txt 和 file2.txt)?

4

1 回答 1

0

必须替换以下代码。

for action, file in results:
  full_filename = os.path.join (path_to_watch, file)
  if not os.path.exists (full_filename):
    file_type = "<deleted>"
  elif os.path.isdir (full_filename):
    file_type = 'folder'
  else:
    file_type = 'file'
  yield (file_type, full_filename, ACTIONS.get (action, "Unknown"))

通过此代码:

for action, file in results:
  if (file != 'file1.txt' and file != 'file2.txt'): #here you cut the check of the files you don't want.
    full_filename = os.path.join (path_to_watch, file)
    if not os.path.exists (full_filename):
      file_type = "<deleted>"
    elif os.path.isdir (full_filename):
      file_type = 'folder'
    else:
      file_type = 'file'
    yield (file_type, full_filename, ACTIONS.get (action, "Unknown"))
于 2014-06-11T13:37:57.560 回答