使用FSO修改文件特定内容的函数

使用FSO修改文件特定内容的函数function FSOchange(filename,Target,String)Dim objFSO,objCountFile,FiletempDataSet objFSO = Server.CreateObject(“Scripting.FileSystemObject”)Set objCountFile = objFSO.OpenTextFile(Server.MapPath(fil

大家好,又见面了,我是你们的朋友全栈君。function FSOchange(filename,Target,String)

Dim objFSO,objCountFile,FiletempData

Set objFSO = Server.CreateObject(“Scripting.FileSystemObject”)

Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)

FiletempData = objCountFile.ReadAll

objCountFile.Close

FiletempData=Replace(FiletempData,Target,String)

Set objCountFile=objFSO.CreateTextFile(Server.MapPath(filename),True)

objCountFile.Write FiletempData 

objCountFile.Close

Set objCountFile=Nothing

Set objFSO = Nothing

End Function

””使用FSO读取文件内容的函数

function FSOFileRead(filename)

Dim objFSO,objCountFile,FiletempData

Set objFSO = Server.CreateObject(“Scripting.FileSystemObject”)

Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)

FSOFileRead = objCountFile.ReadAll

objCountFile.Close

Set objCountFile=Nothing

Set objFSO = Nothing

End Function

””使用FSO读取文件某一行的函数

function FSOlinedit(filename,lineNum)

if linenum < 1 then exit function

dim fso,f,temparray,tempcnt

set fso = server.CreateObject(“scripting.filesystemobject”)

if not fso.fileExists(server.mappath(filename)) then exit function

set f = fso.opentextfile(server.mappath(filename),1)

if not f.AtEndofStream then

tempcnt = f.readall

f.close

set f = nothing

temparray = split(tempcnt,chr(13)&chr(10))

if lineNum>ubound(temparray)+1 then

  exit function

else

  FSOlinedit = temparray(lineNum-1)

end if

end if

end function

””使用FSO写文件某一行的函数

function FSOlinewrite(filename,lineNum,Linecontent)

if linenum < 1 then exit function

dim fso,f,temparray,tempCnt

set fso = server.CreateObject(“scripting.filesystemobject”)

if not fso.fileExists(server.mappath(filename)) then exit function

set f = fso.opentextfile(server.mappath(filename),1)

if not f.AtEndofStream then

tempcnt = f.readall

f.close

temparray = split(tempcnt,chr(13)&chr(10))

if lineNum>ubound(temparray)+1 then

  exit function

else

  temparray(lineNum-1) = lineContent

end if

tempcnt = join(temparray,chr(13)&chr(10))

set f = fso.createtextfile(server.mappath(filename),true)

f.write tempcnt

end if

f.close

set f = nothing

end function

””使用FSO添加文件新行的函数

function FSOappline(filename,Linecontent)

dim fso,f

set fso = server.CreateObject(“scripting.filesystemobject”)

if not fso.fileExists(server.mappath(filename)) then exit function

set f = fso.opentextfile(server.mappath(filename),8,1)

f.write chr(13)&chr(10)&Linecontent

f.close

set f = nothing

end function

””读文件最后一行的函数

function FSOlastline(filename)

dim fso,f,temparray,tempcnt

set fso = server.CreateObject(“scripting.filesystemobject”)

if not fso.fileExists(server.mappath(filename)) then exit function

set f = fso.opentextfile(server.mappath(filename),1)

if not f.AtEndofStream then

tempcnt = f.readall

f.close

set f = nothing

temparray = split(tempcnt,chr(13)&chr(10))

  FSOlastline = temparray(ubound(temparray))

end if

end function

‘还有,创建文件夹:

sub CreateFolder(Foldername)

Set afso = Server.CreateObject(“Scripting.FileSystemObject”)

  if afso.folderexists(server.mappath(Foldername))=true then

  else

   afso.createfolder(server.mappath(foldername))

  end if

set afso=nothing

end sub

‘用法,createfolder(foldername)

遍历目录以及目录下文件的函数

function bianli(path)

set fso=server.CreateObject(“scripting.filesystemobject”) 

on error resume next

set objFolder=fso.GetFolder(path)

set objSubFolders=objFolder.Subfolders

for each objSubFolder in objSubFolders 

nowpath=path + “/” + objSubFolder.name

Response.Write nowpath

set objFiles=objSubFolder.Files

for each objFile in objFiles

Response.Write “<br>—”

Response.Write objFile.name

next

Response.Write “<p>”

bianli(nowpath)’递归

next 

set objFolder=nothing

set objSubFolders=nothing

set fso=nothing

end function

%>

<%

‘bianli(“d:”) ‘遍历d:盘

%>

<%

‘替换指定文件内字符串的函数

function FSOlineedit(filename,Target,String)

Dim objFSO,objCountFile,FiletempData

Set objFSO = Server.CreateObject(“Scripting.FileSystemObject”)

Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)

FiletempData = objCountFile.ReadAll

objCountFile.Close

FiletempData=Replace(FiletempData,Target,String)

    Set objCountFile=objFSO.CreateTextFile(Server.MapPath(filename),True)

objCountFile.Write FiletempData 

objCountFile.Close

Set objCountFile=Nothing

Set objFSO = Nothing

End Function

response.write FSOlineedit(“test.txt”,”世界”,”明天是一个好天去”)

%>

保持刷新文本框中的值

<HTML>

<HEAD>

<META NAME=”save” CONTENT=”history”>

<STYLE>

   .saveHistory {behavior:url(#default#savehistory);}

</STYLE>

<title>保持刷新文本框中的值</title></HEAD>

<BODY>

<INPUT class=saveHistory type=text id=oPersistInput>

</BODY>

</HTML>

ASP中连接数据库的5种方法

ASP中连接数据库的5种方法 

(01-3-30 199) 

from: chinaasp.com by caoli 

第一种 – 这种方法用在ACCESS中最多 

strconn = “DRIVER=Microsoft Access Driver (*.mdb);DBQ=” & Server.MapPath(“aspfree.mdb”) 

set conn = server.createobject(“adodb.connection”) 

conn.open strconn 

第二种-这种方法用在SQL SERVER中多 

strconn = “Driver={SQL 

Server};Description=sqldemo;SERVER=127.0.0.1;UID=LoginID;PWD=Password;DATABASE=Database_Name 

set conn = server.createobject(“adodb.connection”) 

conn.open strconn 

第三种 

strconn=”Driver={MicrosoftAccessDriver(*.mdb)};” &_ 

“DBQ=F:/Inetpub/wwwroot/somedir/db1.mdb;DefaultDir=f:/Inetpub/wwwroot/somedir;uid=LoginID;” &_ 

“pwd=Password;DriverId=25;FIL=MSAccess;” set conn = server.createobject(“adodb.connection”) 

conn.open strconn 

第四种运用系统数据源 

The following uses a Data Source Name: 

set conn = server.createobject(“adodb.connection”) 

conn.open “Example” 

第五种运用ODBC数据源,前提是你必须在控制面板的ODBC中设置数据源 

set rs = server.createobject(“adodb.recordset”) 

rs.open “tblname”, “DSNName”, 3, 3 

汉字判断(js判断)

for(i=0;i<realname.length;i++){

  char=realname.charCodeAt(i);  

  if(!(char>255)){  

   alert(“真实姓名应为汉字!”);

   userform.realname.focus();

   return false;

   }

  }

”身份证真伪

”id 省份证号

”birthday生日,yyyy-mm-dd格式

”sex性别,值为”男:1″,”女:0″

id = “460102800925121”

birthday = “1980-09-25”

sex = 1 

IF idcard_check(id,birthday,sex) Then

   response.write “不错”

else

   response.write “**”

End if

Function idcard_check(id,birthday,sex)

If len(id)<>15 and len(id)<>18 then

    idcard_check=false

    Exit Function

Else

    For i=1 to len(id)

       temp=mid(id,i,1)

       If temp<“0″ or temp>”9” Then

           idcard_check=False

           Exit Function

       End if

    Next

    bdl=left(birthday,4) & mid(birthday,6,2) & mid(birthday,9,2)

    bds=mid(birthday,3,2) & mid(birthday,6,2) & mid(birthday,9,2)

    If len(id)=15 Then

        If mid(id,7,6)<>bds Then

            idcard_check=False

            Exit Function

        End if

        If int(mid(id,15,1)) Mod 2 = 1 And sex=1 Then

            idcard_check=True

            Exit Function

  ElseIf int(mid(id,15,1)) Mod 2 = 0 And sex=0 Then

            idcard_check=True

            Exit Function

  Else

      idcard_check=False

            Exit Function

        End if

    Else

        If mid(id,7,8)<>bdl Then

            idcard_check=False

            Exit Function

        End if

        If int(mid(id,17,1)) Mod 2 = 1 And sex=1 Then

            idcard_check=False

            Exit Function

  ElseIf int(mid(id,17,1)) Mod 2 = 0 And sex=0 Then

            idcard_check=False

            Exit Function

  Else

   idcard_check=False

            Exit Function

        End if

    End if

End if

idcard_check=True

End function

11=”北京”

12=”天津”

13=”河北”

14=”山西”

15=”内蒙古”

21=”辽宁”

22=”吉林”

23=”黑龙江”

31=”上海”

32=”江苏”

33=”浙江”

34=”安徽”

35=”福建”

36=”江西”

37=”山东”

41=”河南”

42=”湖北”

43=”湖南”

44=”广东”

45=”广西”

46=”海南”

50=”重庆”

51=”四川”

52=”贵州”

53=”云南”

54=”西藏”

61=”陕西”

62=”甘肃”

63=”青海”

64=”宁夏”

65=”新疆”

71=”台湾”

81=”香港”

82=”澳门”

91=”国外”

生成一个不重复的随即数字

Sub CalCaPiao()

Dim strCaiPiaoNoArr() As String

Dim strSQL As String

Dim strCaiPiaoNo As String

strCaiPiaoNo = “01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33”

Dim StrTempArr(7) As String

Dim strZhongJiangArr(7) As String

strCaiPiaoNoArr = Split(strCaiPiaoNo, “,”)

Dim intRand As Integer

Dim i As Integer

Dim j As Integer

i = 0

Dim find As Boolean

Do While True

find = False

Randomize

intRand = Int((33 * Rnd) + 1)

For j = 0 To i – 1

If StrTempArr(j) = CStr(intRand) Then

find = True

End If

Next

If Not find Then

StrTempArr(j) = CStr(intRand)

strZhongJiangArr(i) = CStr(intRand)

‘Text1(i) = strZhongJiangArr(i)

i = i + 1

If i = 7 Then

Exit Do

End If

End If

Loop

End Sub

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/138663.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 内存或磁盘空间不足,excel无法再次打开_打开文件显示内存或磁盘空间不足

    内存或磁盘空间不足,excel无法再次打开_打开文件显示内存或磁盘空间不足在网络上下载的文件,使用EXCEL打开的时候提示“内存或磁盘空间不足,MicrosoftExcel无法再次打开或保存任何文档。”,针对这个问题,装机之家小编特地在网上搜罗了具体解决方法,但是网上提

    2022年8月4日
    6
  • linux tty 软件包,linux学习之安装ttylinux(世界最小的linux操作系统)(转载)

    linux tty 软件包,linux学习之安装ttylinux(世界最小的linux操作系统)(转载)第一步,用WinRAR解压缩bootcd-i486-8.1.iso.gz,变成,bootcd-i486-8.1.iso镜像文件备用。第二步,在VirtualBox中新建一个虚拟电脑,并指定内存大小和硬盘大小,我们可以设定为内存256M,硬盘512M。第三步,指定虚拟光驱为bootcd-i486-8.1.iso镜像文件,双击新建的虚拟电脑图标启动即可。第四步,用虚拟光驱启动后,进入系统:输入用户名…

    2022年8月12日
    6
  • zencart模板制作步骤详解

    zencart模板制作步骤详解
    1,在includes/template下面新建个文件夹叫你新模板的名字就可以了,这里我就叫yourname

    2,把includes/template/defalut_template 这个文件夹下面的所有的文件夹和文件复制到你刚刚新建的文件夹里面去yourname

    3,把template_info.php这个文件用dw打开,出现在你眼前的是php代码这个你可以不用管,你只用把[$template_name=’DefaultTemplate’;

    2022年7月27日
    3
  • 安卓基础(十五)[通俗易懂]

    安卓基础(十五)

    2022年1月28日
    40
  • java heap space 什么意思_java heap space是什么意思?

    java heap space 什么意思_java heap space是什么意思?因为程序要从数据读取近10W行记录处理,当读到9W的时候就出现java.lang.OutOfMemoryError:Javaheapspace这样的错误。javaheapspace的意思为“java堆空间”。在网上一查可能是JAVA的堆栈设置太小的原因。跟据网上的答案大致有这两种解决方法:1、设置环境变量setJAVA_OPTS=-Xms32m-Xmx512m可以根据自己机器的…

    2022年7月7日
    40
  • mysql窗口函数rank_rank函数降序排名

    mysql窗口函数rank_rank函数降序排名窗口函数MySQL8.0之后支持窗口函数。窗口指的是记录集合,窗口函数是指在某种条件的记录集合上执行的特殊函数。静态窗口是指不同的记录对应的窗口大小是固定的,而滑动窗口是指随着记录的不同窗口的大小是动态变化的。窗口函数分类1)专用窗口函数,包括后面要讲到的rank,dense_rank,row_number等专用窗口函数。2)聚合函数,如sum.avg,count,max,min等注意事项窗口函数原则上只能写在select子句中,因为窗口函数是对where或者groupby子句

    2022年10月4日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号