-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfolder.lua
More file actions
172 lines (136 loc) · 3.36 KB
/
folder.lua
File metadata and controls
172 lines (136 loc) · 3.36 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
--conding:utf-8
package.path=package.path..";./luagy/?.lua"
Class=require("grammar.class")
path=require "pl.path"
require"lfs"
File=require("file")
MDFile = require("mdfile")
local Folder=Class(function(self,path)
self.path=path
--目前目录下的文件
self.files={}
self.dirs={}
--md文件里面有描述的文件
self.dirsinfo={}
self.filesinfo={}
self:init(path)
end)
--public:
--- 初始化对象
-- @param path
--
function Folder:init(path)
end
--===========功能==============
--- 模仿ls命令
-- @param arg
--
function Folder:list(arg)
self:getFiles()
self:readMDfile()
for k,v in pairs(self.dirs) do
if(self.dirsinfo[v.filename]) then
print(self.dirsinfo[v.filename]:toString())
else
print(v:toString())
end
end
for k,v in pairs(self.files) do
if(self.filesinfo[v.filename]) then
print(self.filesinfo[v.filename]:toString())
else
print(v:toString())
end
end
end
--- edit 编辑命令
-- * 文件不存在 -1
-- * 文件存在
-- * MD文件不存在 000
-- * 是否增加父文件夹描述 0_0
-- * MD文件存在 100
-- * 信息存在 010
-- * 信息不存在 000
-- @param filepath
---
--[[ or
]]
function Folder:edit(filepath)
if(not path.exists(filepath)) then
print("file:`"..filepath.."` don't exists")
return -1
end
r=self:readMDfile()
if(r==false) then
--MD文件不存在
mdf=MDFile(self.path.."/FOLDER.MD")
io.write("Do you want add this folder decscript to FOLDER.MD?[Y/n]")
r=io.read("*l")
if(r=="" or r=="Y" or r=="y" or r=="yes") then
print("Please input folder decscript:")
io.write(">")
dec=io.read("*l")
end
return
end
infos=self.dirsinfo
if(path.isfile(filepath)) then
infos=self.filesinfo
end
if(infos[filepath]) then
--信息存在
return
end
--信息不存在
end
--===========输入输出=============
function Folder:inputDirDesc()
end
--增加注释
function Folder:addDescript(filename,desc)
end
--增加属性
function Folder:addAtrr(filename,attr)
end
--private
--载入目前目录的所有文件和目录
local sep = "/"
local upper = ".."
function Folder:getFiles()
for file in lfs.dir(self.path) do
if file ~= "." and file ~= ".." then
local p = self.path..sep..file
local attr = lfs.attributes (p)
if attr.mode == "directory" then
self.dirs[file]=File(file)
else --is file
self.files[file]=File(file)
end
end
end
end
--读入MD描述文件
function Folder:readMDfile()
mdf=MDFile(self.path.."/FOLDER.MD")
if(mdf.isexist==false) then
return false
end
for k,l in pairs(mdf.dirline) do
d=File()
d:initFromMDstr(l)
if(d.parseSuccess) then
self.dirsinfo[d.filename]=d
end
end
for k,l in pairs(mdf.fileline) do
d=File()
d:initFromMDstr(l)
if(d.parseSuccess) then
self.filesinfo[d.filename]=d
end
end
end
--写入MD描述文件
function Folder:wirteMDfile()
end
return Folder