当前位置: 首页 > 图文教程 > 网络编程 > ASP > 一些源程序 - 获得文件大小和字符串处理

ASP
二文件上传,才30行代码
用ASP制作在线测试
三级下拉框连动的数据库版
用户注册及跟踪代码(一)
用户注册及跟踪代码(二)
用户注册及跟踪代码(三)
ASP.Net写的浏览器间谍
ASP实现播放Flash的例子
用DataList控件开发一个简单的留言本程序
aspemail组件的应用
编写数据库脚本
用ASP建立邮件列表
用ASP技术编制隐藏用户密码程序
用ASP统计用户在站点的停留时间
HTTP方式上载文件的ASP程序实例
使用VB编写纯ASP程序
用ASP统计用户在站点的停留时间(1)
用ASP统计用户在站点的停留时间(2)
用ASP实现论坛的UBB功能(一)
用ASP实现论坛的UBB功能(二)

ASP 中的 一些源程序 - 获得文件大小和字符串处理


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 43 ::
收藏到网摘: n/a

  Formats passed string based on length. Perfect for emails and text files.
---------------------------------------------------------------------------------------
<%
' Company: Sabra Inc
' Author: Dave Hoffenberg
' Date: 10/5/00
' Function: Formats passed string based on length.  Perfect for emails and text files.
' Freeware

Function Padding(Value, Length)
' If the length of the value is less than the variable 'length'
If Len(Value) < Length Then
charcount = Length - len(Value)

for i = 1 to (charcount - 1)

padding = padding & " "

next

mystring = Value & padding
' If the length of the value is greater than the variable 'length'
Elseif len(Value) > Length Then
mystring = Left(Value,Length)

Else
set mystring = Value

End If

Padding = mystring

End Function


Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile(Server.MapPath("test.txt"), True)

MyFile.WriteLine Padding("this is a test", 25) & "end of line."

Set fso = Nothing
Set MyFile = Nothing

response.write "done"
%>

Retrieves file size(K) of any file passed to it.
---------------------------------------------------------------------------

<%
' Company: Sabra Inc
' Author: Dave Hoffenberg
' Function: Retrieves file size(K) of any file name passed to it.
' Freeware

Function ShowFileSize(filespec)
    file = Server.MapPath(filespec)
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(file) Then
    Set f = fso.GetFile(file)
intSizeB = f.Size
    intSizeK = Int((intSizeB/1024) + .5)
    If intSizeK = 0 Then intSizeK = 1
     ShowFileSize = intSizeK & "k"
Else
 ShowFileSize = "File Doesn't Exist"
End If
Set fso = Nothing
End Function

response.write ShowFileSize("test.txt")
%>