Next / Previous / Contents / Shipman's homepage

12. visitor(): Process one directory's contents

This function is called by os.path.walk() once for each directory in or under the specified base directory.

deduper
# - - -   v i s i t o r

def visitor(fileData, dirName, nameList):
    '''Visitor function for os.path.walk

      [ (fileData is a FileData instance) and
        (dirName is an absolute path to a directory) and
        (nameList is a list of names in that directory) ->
          fileData  +:=  rows for non-soft-link files of size LARGE_SIZE
              or larger in or under directory (dirName)
          sys.stderr  +:=  error messages for unreadable files
              in directory (dirname) ]
    '''
    #-- 1
    for name in sorted(nameList):
        #-- 1 body
        # [ name is a name in directory (dirName) ->
        #     let
        #       filePath == os.path.join(dirName, name)
        #     in ->
        #       if filePath refers to a readable non-link file of size
        #       LARGE_SIZE or greater ->
        #         fileData  +:=  a new FilePath with path (filePath)
        #             and hash (sha256 hex digest of that file)
        #       else if filePath is unreadable ->
        #         sys.stderr  +:=  error message, (name) is unreadable
        #       else -> I ]
        addFile(fileData, dirName, name)