FileSync Examples

The submodule simply_nwb.transferring.filesync contains utility classes for synchronizing files across filesystems

OneWayFileSync

OneWayFileSync takes files and copies them to another directory, waiting for changes in the source directory, and does a checksum check to ensure it only copies over changed files

Simple OneWayFileSync Example

 1from simply_nwb.transferring import OneWayFileSync
 2
 3
 4def main():
 5    OneWayFileSync(
 6        # Will watch the folder 'from_src' for files and changes
 7        "../data/from_src",
 8        # Will copy all new files / changes to this directory
 9        "../data/to_dst",
10        # Include all files, could also do '*.txt' for all txt files, etc
11        "*",
12        delete_on_copy=True  # Will delete the file/folder from the src directory upon successful copy
13    ).start()
14    # Program will run continuously until killed
15
16
17if __name__ == "__main__":
18    main()

Complex OneWayFileSync Example

 1from simply_nwb.transferring import OneWayFileSync
 2
 3
 4def remove_extension(filename):
 5    return filename.split(".")[0]
 6
 7
 8def main():
 9    OneWayFileSync(
10        # Will watch the folder 'from_src' for files and changes
11        source_directory="../data/from_src",
12        # Will copy all new files / changes to this directory
13        destination_directory="../data/to_dst",
14        watch_file_glob={
15            # Copy all bmp files
16            "*.bmp": {},
17            # Will copy all <name>.txt files to 'TextFiles/myfile_name_me_<name>.py'
18            # Will create directories under the destination folder
19            "*.txt": {
20                "filename": "TextFiles/myfile_{name}.py",
21                "name_func": remove_extension
22            }
23        },
24        delete_on_copy=True # Will delete the file/folder from the src directory upon successful copy
25    ).start()
26    # Program will run continuously until killed
27
28
29if __name__ == "__main__":
30    main()