目录,文件名,后缀名,文件大小,文件属性函数


'判断文件名windows下的目录名是否合法
Function IsValidWindowsFolderName(strFolderName)
IsValidWindowsFolderName=TRUE
sErrorStr=Array("/","/",":","*","?","""","<",">","|")
iNameLength=Len(strFolderName)
'判断目录长度是否合法
If iNameLength<1 or iNameLength=null or iNameLength>255 Then
IsValidWindowsFolderName=FALSE
Else
'判断目录名字中是否有非法字符
 For i=0 To 8
 If instr(strFolderName,sErrorStr(i)) Then
 IsValidWindowsFolderName=FALSE
 exit Function
 End If
 Next
End If
End Function

'判断文件名windows下的文件名是否合法
Function IsValidWindowsFileName(strFileName)
IsValidWindowsFileName=TRUE
sErrorStr=Array("/","/",":","*","?","""","<",">","|")
iNameLength=Len(strFileName)
If iNameLength<1 or iNameLength=null or iNameLength>255 Then
 response.Write("<script language=javascript>alert('文件名长度不正确,按确定返回重新填写');history.back();</script>")
 response.End()
IsValidWindowsFileName=FALSE
Else
if instr(strFileName,".htm")>0 or instr(strFileName,".html")>0 or instr(strFileName,".asp")>0 or instr(strFileName,".shtml")>0 then
 For i=0 To 8
 If instr(strFileName,sErrorStr(i)) Then
 response.Write("<script language=javascript>alert('文件名有非法字符,按确定返回重新填写');history.back();</script>")
 response.End()
 IsValidWindowsFileName=FALSE
 exit Function
 End If
 Next
else
 response.Write("<script language=javascript>alert('文件名后缀名不正确,按确定返回重新填写');history.back();</script>")
 response.End()
IsValidWindowsFileName=FALSE
end if
End If
End Function
 
'*******************************************
'函数作用:取得文件路径
'*******************************************
Function GetLocalPathDir(ByVal D)
 If Len(D) = 0 then Exit Function
 if instr(strFileName,"/")<0 then
 GetLocalPathDir=D
 else 
 GetLocalPathDir=Left(D,InStrRev(D,"/")-1)
 end if
End Function
'*******************************************
'函数作用:取得文件名
'*******************************************
Function GetLocalPathFile(ByVal D)
 If Len(D) = 0 then Exit Function
 if instr(strFileName,"/")<0 then
 GetLocalPathFile=D
 else 
 GetLocalPathFile=Right(D,Len(D)-InStrRev(D,"/"))
 end if
End Function
'*******************************************
'函数作用:取得文件后缀名
'*******************************************
Function GetLocalPathFileExt(ByVal D)
 If Len(D) = 0 then Exit Function
 if instr(strFileName,".")<0 then  Exit Function
 GetLocalPathFileExt=Right(D,Len(D)-InStrRev(D,"."))
End Function

'*******************************************
'函数作用:取得文件的后缀名
'*******************************************
Function GetExtensionName(name)
 Dim ArrayFileName
 ArrayFileName=Split(name,".")
 GetExtensionName=ArrayFileName(Ubound(ArrayFileName))
End Function

'*******************************************
'函数作用:格式化文件的大小
'*******************************************
Function GetFileSize(size)
 Dim FileSize
 FileSize=size / 1024
 FileSize=FormatNumber(FileSize,2)
 If FileSize < 1024 and FileSize > 1 then
  GetFileSize="<font color=red>"& FileSize & "</font>&nbsp;KB"
 ElseIf FileSize >1024 then
  GetFileSize="<font color=red>"& FormatNumber(FileSize / 1024,2) & "</font>&nbsp;MB"
 Else
  GetFileSize="<font color=red>"& Size & "</font>&nbsp;Bytes"
 End If
End Function
'*******************************************
'函数作用:格式化文件属性
'*******************************************
Function GetFileAttr(AttributesNo)
 Dim AttributesName
 Select Case AttributesNo
 Case 0
 AttributesName="Normal"
 Case 1
 AttributesName="ReadOnly"
 Case 2
 AttributesName="Hidden"
 Case 4
 AttributesName="System"
 Case 8
 AttributesName="Volume"
 Case 16
 AttributesName="Directory"
 Case 32
 AttributesName="Archive"
 Case 64
 AttributesName="Alias"
 Case 128
 AttributesName="Compressed"
 Case else
 AttributesName=AttributesNo
 end Select 
 GetFileAttr=AttributesName
 'Normal              0        一般文件,未设置属性
    'ReadOnly            1        只读文件,属性为读/写
    'Hidden              2        隐藏文件,属性为读/写
    'System              4        系统文件,属性为读/写
    'Volume              8        磁盘驱动器卷标,属性为只读
    'Directory           16       文件夹或目录,属性为只读
    'Archive             32       自上次备份后已经改变的文件,属性为读/写
    'Alias               64       链接或快捷方式,属性为只读
    'Compressed          128      压缩文件,属性为只读 
 
End Function

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

疾风铸境

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值