-[[
@引用:require("FileLib")
@调用:fileLib.createFolder(path)
@功能:
1.创建文件夹
2.连续创建文件夹
3.删除文件夹所有内容
4.删除空文件夹/文件
5.获取某个文件夹下的所有文件
6.获取文件夹下的一级文件及文件夹table
7.判断文件是否存在
8.判断文件夹是否存在
]]
fileLib={
createFolder=function(path)
os.execute("mkdir "..path)
end;
createAllFolder=function(path)
local path_tb={}
local new_path=""
for s in string.gmatch(path,"([^'/']+)") do
if s~=nil then
table.insert(path_tb,s)
end
end
for k,v in ipairs(path_tb) do
if k==1 then
new_path=v
else
new_path=new_path.."/"..v
end
if os.execute("cd "..new_path) then
print(new_path.." exist")
else
print(new_path.." do not exist")
os.execute("mkdir "..new_path)
end
end
print("create suc")
end;
deleteAllFolder=function(folderPath)
os.execute("rm -rf "..folderPath)
end;
deleteAllFolder=function(folderPath)
os.remove(folderPath)
end;
getAllFileInFolder=function(folderPath,backupPath)
local file_tb={}
local fileList={};
local newPath=""
local f=io.open(backupPath.."/file.txt",'a')
fileList=fileLib.getFileList(folderPath)
for i= 1, #fileList do
if string.find(fileList[i],"%.")==nil then
newPath=folderPath.."/"..fileList[i];
fileLib.getAllFileInFolder(newPath,backupPath)
else
f:write(folderPath.."/"..fileList[i].."\n")
end
end
f:close();
end;
getFileList=function(path)
local a = io.popen("ls "..path.."/");
local fileTable = {};
if a==nil then
else
for l in a:lines() do
table.insert(fileTable,l)
end
end
return fileTable;
end;
isFileExist=function(path)
f=io.open(path,"w")
return f~=nil and f:close();
end;
isFolderExist=function (folderPath)
return os.execute("cd "..folderPath)
end
}