Last active
December 4, 2022 23:34
-
-
Save Beyarz/ce62f338a374598c68cb60d933bdc99c to your computer and use it in GitHub Desktop.
File watcher, track every file in the same directory for changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Directory tracker | |
begin | |
require "digest" | |
rescue LoadError | |
puts "Digest module not found." | |
end | |
files = Dir["*"] | |
files.delete(__FILE__) | |
fileNames = [] | |
fileHash = [] | |
for each in files | |
fileNames << each.split(".")[0] | |
fileHash << Digest::MD5.file(each).hexdigest | |
end | |
begin | |
while true | |
for row in (0..files.length-1) | |
if fileHash[row] != Digest::MD5.file(files[row]).hexdigest | |
puts | |
puts "File: "+fileNames[row] | |
puts "Hash: "+fileHash[row] | |
fileHash[row] = Digest::MD5.file(files[row]).hexdigest | |
# Do what ever you want with the file | |
# Use fileHash[row] as reference | |
end | |
end | |
end | |
rescue Interrupt | |
puts "Killing the infinite loop." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment