Skip to content

Instantly share code, notes, and snippets.

@rixth
Created August 30, 2009 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rixth/177908 to your computer and use it in GitHub Desktop.
Save rixth/177908 to your computer and use it in GitHub Desktop.
# File you want to get before it's deleted
fileToSave = 'blarblarblar'
# If you want to specify a little bit we can trim off the end
# do it here in bytes. This may make the script more likely to
# save your file.
buffer = 0;
# Wait for the file to be created
print "Okay, please start the process that outputs "+fileToSave+"\n";
while true
break if !File.size?(fileToSave).nil?
end
# First pass to get maximum file size before nuke
print "Thanks, running loop to determine the maximum file size before the file is deleted\n";
maxSize = 0;
while true
size = File.size?(fileToSave)
if size
if size > maxSize
maxSize = size
end
else
break
end
end
print "Max size appears to be "+maxSize.to_s+" bytes. Please start the same process again.\n"
# Wait for file to be written again
while true
break if !File.size?(fileToSave).nil?
end
print "Sweet. Will move the file to saved-"+fileToSave+" when it reaches that size again\n";
# Watch it until it gets to our target size
sizeToCheck = maxSize-buffer
while true
size = File.size?(fileToSave)
if size
if size >= sizeToCheck
File.rename(fileToSave, 'saved-'+fileToSave)
break
end
end
end
print "Done!\n\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment