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

2016-01-29 17:14 1 1 收藏

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

【 tulaoshi.com - ASP 】

  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")
%

 

来源:https://www.tulaoshi.com/n/20160129/1500755.html

延伸阅读
FillString函数有两个参数,一个是用来重复填充的字符,另一个是填充后的字符串长度。然后它返回填充后的字符串,重复次数由填充字符的个数和填充后字符串长度决定。 该函数建立一个循环,循环次数基于所要求的字符串长度。循环步长有参数Value(即用来重复填充的子字符串)的长度决定。该函数把参数Value作为工作字符串,重复后按所要...
笔者使用Windows Sever 2003 IIS服务+ASP网站管理系统为单位架设网站,但当以管理员身份上传超过200KB的文件时,浏览器弹出错误页面,内容为“Request 对象 错误 'ASP 0104 : 80004005'”。经过查阅相关资料,解决方法如下: 第一步:在“开始→运行”中输入“CMD”打开命令提示符窗口,输入“net stopw3svc”后回车,屏幕显示World W...
标签: Web开发
自动将双字节字符长度计算为2,取字符时也按照单字节的长度取,如2即取1个汉字或两个字母,1取一个汉字或字母。 [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
标签: Web开发
去掉字符串中匹配 的字符串 代码如下: /** * 去掉字符串中匹配 的字符串 * * @author zhujie * @return String regex 要替换的内容 value 字符串 state 替换的内容变成什么 */ public static String toRegex(String regex, String value, String state) { Pattern p = Pattern.compile(regex); Matcher m = p.matcher(value); String...
在写SQL语句时,需要对不同类型的数据分别加上#号,""号等来表示,用以下函数,就可以实现操作的简化.不管是什么类型,只需用这个Q函数转化一下,不需动手加格式化符号,就OK了.实在是方便.本人一直在用它,实在是方便. Function Q(ByVal SqlVariable As Variant) As String'-----------------------------------------' ...

经验教程

209

收藏

71
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部