使用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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • matlab画三维图形_matlab的三维函数

    matlab画三维图形_matlab的三维函数对散点图拟合三维网格图形:num=xlsread(‘data_2011a.xls’,’B4:E322′)//读取出该区域的数据作为表格A=num(:,1)//从B矩阵取出第一列的所有行B=num(:,2)C=num(:,3)xx=linspace(min(A),max(A),50);//产生min(A)到max(A)均摊的50个点,目的上拟合离散点数量上的不足yy=linsp…

    2022年10月11日
    0
  • jxls工具导出excel,报错:Cannot load XLS transformer. Please make sure a Transformer implementation is in cl[通俗易懂]

    jxls工具导出excel,报错:Cannot load XLS transformer. Please make sure a Transformer implementation is in cl[通俗易懂]jxls导出excel报错:“`javajava.lang.reflect.InvocationTargetException:nullatsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)~[na:1.8.0_101]atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)~[na:1.8.0_101…

    2022年7月24日
    55
  • 计算机考研复试C语言常见面试题「建议收藏」

    计算机考研复试C语言常见面试题「建议收藏」本文是我2021年考研时准备的复试面试题,现在拿出来给大家分享一下觉得好的点个赞哦,毕竟当初我也是整理了好久,改了好几次版本呢祝大家都上岸!!!!P.S.我当初整理的时候是word,直接复制过来的话代码不会自动变成CSDN的代码块,所以代码我是一段一段重新标记为CSDN代码段的,这样大家看起来舒服点C语言基础目录1、static关键字的作用22、C++和C的区别23、Java的方法重载24、重写和重载25、面向对象编程36、c++可以有多个父类37

    2022年8月29日
    1
  • git的面试题_es面试题

    git的面试题_es面试题GIT常见面试题1. 列举工作中常用的几个git命令?新增文件的命令:gitaddfile或者gitadd.提交文件的命令:gitcommit–m或者gitcommit–a查看工作区状况:gitstatus–s拉取合并远程分支的操作:gitfetch/gitmerge或者gitpull查看提交记录命令:gitreflog2. 提交时发生冲突,你能解释冲突是…

    2022年4月19日
    46
  • 如何查看某个端口被谁占用

    如何查看某个端口被谁占用

    2021年11月23日
    58
  • linux必学的60个命令解释_linux常用命令及用法

    linux必学的60个命令解释_linux常用命令及用法Linux提供了大量的命令,利用它可以有效地完成大量的工作,如磁盘操作、文件存取、目录操作、进程管理、文件权限设定等。所以,在Linux系统上工作离不开使用系统提供的命令。要想真正理解Linux系统,就必须从Linux命令学起,通过基础的命令学习可以进一步理解Linux系统。不同Linux发行版的命令数量不一样,但Linux发行版本最少的命令也有200多个。这里笔者把比较重要和使用频率最多的命令,按照它们在系统中的作用分成下面六个部分一一介绍。◆安装和登录命令:login、shutdown、hal

    2022年9月16日
    0

发表回复

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

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