用FileObject建立标准网站维护(转)

检查MP3文件大小与类型
本文介绍了一种使用VBScript和Scripting.FileSystemObject检查指定目录下所有MP3文件是否超过50KB限制的方法。通过遍历文件夹,检查每个文件的类型和大小,打印出违规文件的路径。

'Always do this: (good programming practice!)
Option Explicit
'Declare our FileSystemObject variable
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

Dim objFolder


Dim strCurrentFolder
strCurrentFolder = "C:Inetpubwwwroot"

Set objFolder = objFSO.GetFolder(strCurrentFolder)

'Declare a file object
Dim objFile

'What is the maximum size of a file in bytes?
Const MaxSize = 5000 '50 KB


'Did we find any violating files?
Dim bolViolators
bolViolators = False

'Now, use a for each...next to loop through the Files collection
For Each objFile in objFolder.Files
  'Check to see if objFile is an MP3
  If LCase(Right(objFile.Name, 4)) = ".mp3" then
'Print out the violating file name and location
Response.Write "MP3 File!
"
Response.Write objFile.Path & "

"

'We found a violator
bolViolators = True
  End if

  'Make sure the file isn't too big
  If objFile.Size > MaxSize then
'Print out the violating file name and location
Response.Write "File is too large! (" & objFile.Size & " bytes)
"
Response.Write objFile.Path & "

"

'We found a violator
bolViolators = True
  End If
Next

'Now, if we didn't have any violating files, say so!
If Not bolViolators then
Response.Write "No violating Files..."
End if

'Clean up...
Set objFSO = Nothing
Set objFolder = Nothing
%>



Sub IterateThroughDirectory(objFolder)
'Process each file to determine if it is larger than 50kb
'or is of type MP3
'What is the maximum size of a file in bytes?
Const MaxSize = 50000 '50 KB

'Now, use a for each...next to loop through the Files collection
For Each objFile in objFolder.Files
  'Check to see if objFile is an MP3
  If LCase(Right(objFile.Name, 4)) = ".mp3" then
'Print out the violating file name and location
Response.Write "MP3 File!
"
Response.Write objFile.Path & "

"
  End if

  'Make sure the file isn't too big
  If objFile.Size > MaxSize then
'Print out the violating file name and location
Response.Write "File is too large! (" & objFile.Size & " bytes)
"
Response.Write objFile.Path & "

"
  End If
Next

Dim objFile
For Each objFile in objFolder.Files
if Lcase(Right(objFile.Name,4)) = ".mp3" then
objDict.Add CStr(iCount), objFile.Path
iCount = iCount + 1
end if
Next

Dim objSubFolder
For Each objSubFolder in objFolder.SubFolders
IterateThroughDirectory objSubFolder
Next
End Sub

Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

Dim strCurrentFolder
strCurrentFolder = "C:Inetpubwwwroot"
Dim objFolder
Set objFolder = objFSO.GetFolder(strCurrentFolder)


IterateThroughDirectory objFolder


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-124710/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10294527/viewspace-124710/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值