-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.php
More file actions
67 lines (54 loc) · 1.71 KB
/
Copy pathutil.php
File metadata and controls
67 lines (54 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
function make_index($file_name, $dir_name)
{
$fp = fopen(__DIR__."/".$file_name, "w");
fwrite($fp, "#index\n");
$tree_result = explode("\n", shell_exec("find ".$dir_name));
//リンク作成用ディレクトリ構造保存配列
$dir_array = array();
for($i = 0; $i < count($tree_result); $i++){
if(!array_key_exists($i, $tree_result))
{
continue;
echo("array key doesn't exist\n");
}
//echo($i."\n");
//ディレクトリ階層数
//chromeから実行時
$dir_class = substr_count($tree_result[$i], "/");
//列挙時の符号
$sign = "";
switch($dir_class%2){
case 0:
$sign = "+ ";
break;
case 1:
$sign = "- ";
break;
}
//列挙時のスペース
$space = "";
for($j=0; $j<$dir_class-1; $j++){
$space .= " ";
}
//ディレクトリかmd, pdfファイルだったらindexに追加
if(substr_count($tree_result[$i], ".")==1){
if($dir_class > 0){
$preg_array = preg_split('/\//', $tree_result[$i]);
fwrite($fp, $space.$sign.$preg_array[count($preg_array)-1]."\n");
$dir_array = array_slice($dir_array, 0, $dir_class-1);
array_push($dir_array, $preg_array[count($preg_array)-1]);
}
}elseif(preg_match('/\.(md|pdf)$/', $tree_result[$i])){
if($dir_class > 1){
$link_address = "";
for($j=0; $j<$dir_class-1; $j++){
$link_address .= $dir_array[$j]."/";
}
$preg_array = preg_split('/\//', $tree_result[$i]);
fwrite($fp, $space.$sign."[".$preg_array[count($preg_array)-1]."](".$link_address.$preg_array[count($preg_array)-1].")\n");
}
}
}
fclose($fp);
}