Skip to content

Instantly share code, notes, and snippets.

@piscisaureus
Created March 8, 2012 00:18
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 piscisaureus/1997507 to your computer and use it in GitHub Desktop.
Save piscisaureus/1997507 to your computer and use it in GitHub Desktop.
var fs = require('fs'),
path = require('path');
// Create a buffer of some size
var buf = new Buffer(1024);
buf.fill(66);
// This will fail
try {
fs.statSync('test/test2/file20');
} catch (e) {
}
// Create a directory with 20 files
fs.mkdirSync("test");
fs.mkdirSync("test/subdir");
fs.mkdirSync("test/subdir/test");
for (var i = 1; i <= 20; i++) {
fs.writeFileSync("test/subdir/test/file" + i, buf);
}
// Rename the directory
fs.rename("test/subdir/test", "test/test2", function(er) {
if (er) throw er;
// Read the directory
var files = fs.readdirSync("test/test2");
console.log(files);
// This file should now be there
fs.statSync('test/test2/file20');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment