Update replace.js

properly count valid files. exit when all of them have been evaluated.