Skip to content

Instantly share code, notes, and snippets.

@Beyarz
Last active December 4, 2022 23:34
Show Gist options
  • Save Beyarz/ce62f338a374598c68cb60d933bdc99c to your computer and use it in GitHub Desktop.
Save Beyarz/ce62f338a374598c68cb60d933bdc99c to your computer and use it in GitHub Desktop.
File watcher, track every file in the same directory for changes.
# 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