|
|
@@ -13,7 +13,7 @@ |
|
|
|
// > php dir2json.php --help |
|
|
|
// ------------------------------------------------------ |
|
|
|
|
|
|
|
$DIR2JSON = '0.2.0'; |
|
|
|
$DIR2JSON = '0.2.1'; |
|
|
|
|
|
|
|
function dir2json($dir) |
|
|
|
{ |
|
|
@@ -46,6 +46,12 @@ function dir2json($dir) |
|
|
|
return $dirList; |
|
|
|
} |
|
|
|
|
|
|
|
function usage($str='', $ret=2) { |
|
|
|
if (!empty($str)) echo $str."\n"; |
|
|
|
echo "For help, try:\n ./dir2json.php -h\n"; |
|
|
|
exit($ret); |
|
|
|
} |
|
|
|
|
|
|
|
// Long and short help opts |
|
|
|
$param = isset($argv[1]) ? $argv[1] : ''; |
|
|
|
if ($param === "-h" || $param === "--help") |
|
|
@@ -93,21 +99,19 @@ $jsonOptions = empty($jsonOptions) ? 0 : constant($jsonOptions); |
|
|
|
|
|
|
|
// If we have a folder to read |
|
|
|
if (!is_dir($targetFolder)) { |
|
|
|
echo "Cannot open folder $targetFolder\n"; |
|
|
|
exit(2); |
|
|
|
if (empty($targetFolder)) $targetFolder = '(empty)'; |
|
|
|
usage("Cannot open folder $targetFolder", 2); |
|
|
|
} |
|
|
|
|
|
|
|
// If we have an output file name |
|
|
|
if (empty($outputFile)) { |
|
|
|
echo "Need a valid output file name (empty)\n"; |
|
|
|
exit(3); |
|
|
|
usage("Need a valid output file name (empty)", 3); |
|
|
|
} |
|
|
|
|
|
|
|
$arr = dir2json($targetFolder); |
|
|
|
$json = json_encode($arr, $jsonOptions); |
|
|
|
if (!file_put_contents($outputFile, $json)) { |
|
|
|
echo "Could not save output file: $outputFile\n"; |
|
|
|
exit(4); |
|
|
|
usage("Could not save output file: $outputFile", 4); |
|
|
|
} |
|
|
|
|
|
|
|
exit(0); |
|
|
|