Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created December 2, 2011 17:42
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 isaacs/1424137 to your computer and use it in GitHub Desktop.
Save isaacs/1424137 to your computer and use it in GitHub Desktop.
var fs = require("fs")
// first, make a directory full of stuff
var dir = "test-dir-" + process.pid
fs.mkdirSync(dir, 0755)
for (var i = 0; i < 1024; i ++) {
fs.writeFileSync(dir + "/" + i, "file " + i)
}
// now we have the test directory.
// give it a second to make sure that there are no further timing issues.
setTimeout(proceed, 1000)
function proceed () {
// readdir and then move it not-quite immediately after.
fs.readdir(dir, function (er, entries) {
setTimeout(function () {
fs.rename(dir, dir + "-renamed", function (er) {
console.error(er || "ok")
})
}, 50)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment