Safe to have multiple processes writing to the same file at the same time? [CentOs 6, ext4]

What you’re doing seems perfectly OK, provided you’re using the POSIX “raw” IO syscalls such as read(), write(), lseek() and so forth. If you use C stdio (fread(), fwrite() and friends) or some other language runtime library which has its own userspace buffering, then the answer by “Tilo” is relevant, in that due to the … Read more

Convert a directory structure in the filesystem to JSON with Node.js

Here’s a sketch. Error handling is left as an exercise for the reader. var fs = require(‘fs’), path = require(‘path’) function dirTree(filename) { var stats = fs.lstatSync(filename), info = { path: filename, name: path.basename(filename) }; if (stats.isDirectory()) { info.type = “folder”; info.children = fs.readdirSync(filename).map(function(child) { return dirTree(filename + “https://stackoverflow.com/” + child); }); } else { … Read more

How can I get a writable path on the iPhone?

There are three kinds of writable paths to consider – the first is Documents, where you store things you want to keep and make available to the user through iTunes (as of 3.2): NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; Secondly, and very similar to the Documents directory, there is the … Read more

How to get directory size in PHP

function GetDirectorySize($path){ $bytestotal = 0; $path = realpath($path); if($path!==false && $path!=” && file_exists($path)){ foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object){ $bytestotal += $object->getSize(); } } return $bytestotal; } The same idea as Janith Chinthana suggested. With a few fixes: Converts $path to realpath Performs iteration only if path is valid and folder exists Skips . and … Read more