Shorter cleaner code less prone to failure - will work for any length, or at least while LoyceV keeps 10k files per folder. Might be faster but in this case I don't think it matters much.
Granted right now what you have works fine so no real need to change until we get to 100 million posts

Your solution indeed looks cleaner.
But I didnt understand why would this bug with a bigger length
var topfolder = top.substring(0, top.length-4);
I am removing the last four digits, no matter the size