         throw err unless err.code is 'EEXIST'
 
     if Date.now() >= nextLogTime
-        percent = 100 * (i + 1) / totalNumIds
-        remaining = totalNumIds - (i + 1)
+        remaining = idFileNames.length
+        percent = 100 * (totalNumIds - remaining) / totalNumIds
         echo "#{percent.toFixed 2}% processed; #{remaining} files remaining."
         nextLogTime = Date.now() + 1000 * 60
 

    path = path.replace /_([A-Z])/g, '$1'
    Path.basename path, Path.extname path

# Now query all the IDs we have:
echo 'Querying content files...'
idFileNames = FS.readdir DIR_BY_ID_PATH, _
totalNumIds = idFileNames.length
echo "#{totalNumIds} files found."

# Now go through each ID,and process it, outputting percentage every minute:
echo 'Processing...'
nextLogTime = Date.now() + 1000 * 60

for idFileName, i in idFileNames
    # Skip non-content files:
    continue if (Path.extname idFileName) isnt '.json'

    id = getIdForFilePath idFileName
    idPath = getFilePathForId id  # full path, not just file name

config = require '../config'
crypto = require 'crypto'
echo = console.log
flows = require 'streamline/lib/util/flows'
FS = require 'fs'
Path = require 'path'

