請問OpenTextFile()中怎樣用相對路徑(急!!在線等)

阿林 2003-08-21 10:45:34
請問OpenTextFile()中怎樣用相對路徑

我可以用絕對路徑打開指定文件,但用相對路徑時,總說找不到PATH.
不知怎樣做才行,另外能否根據相對路徑,取得絕對路徑.請付實例,,謝謝..

急!!!!!!!!!!!在線等
...全文
64 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sailor001 2003-08-21
  • 打赏
  • 举报
回复
使用fso.OpenTextFile(server.mappath("文件名"))
bullion 2003-08-21
  • 打赏
  • 举报
回复
代码?
pp4u 2003-08-21
  • 打赏
  • 举报
回复
用server.MapPath
Brookes 2003-08-21
  • 打赏
  • 举报
回复
set fso=server.CreateObject("Scripting.FileSystemObject")
filename=server.MapPath("../1.asp")
set mFile=fso.OpenTextFile(filename)
# $language = "VBScript" # $interface = "1.0" '作者;小怪兽怪瘦 Sub Main Const ForReading = 1, ForWriting = 2, ForAppending = 8 Dim fso,file1,line,str1,params Set fso = CreateObject("Scripting.FileSystemObject") Set file1 = fso.OpenTextFile("D:\backup\list.txt",Forreading, False) crt.window.show 3 crt.Screen.Synchronous = True do while file1.AtEndOfStream True '读取每一行 line = file1.ReadLine '分割IP,用户名,密码 特权密码 型号简写(z m h b) 位置 params = Split (line) ip = params(0) user = params(1) password = params(2) su = params(3) mode = params(4) whereis = params(5) crt.session.LogFileName = "D:\backup\log\"&ip&"_"&whereis&"_20190620.txt" '提供日志,修改后面日期即可 crt.session.Log(true) crt.Session.Connect ( "/SSH2 /L "&user&" /PASSWORD "&password&" "&ip) '建立SSH连接 if mode = "m" then 'm 代表迈普型号 crt.Screen.Send "enable" & chr(13) crt.Screen.WaitForString "assword:" crt.Screen.Send params(3) & chr(13) crt.Screen.WaitForString "#" '关闭more提示 crt.Screen.Send "more off" & chr(13) crt.Screen.WaitForString "#" '执行命令集 Set cmdfile = fso.OpenTextFile("D:\backup\cmd-mp.txt",Forreading, False) do while cmdfile.AtEndOfStream True line2 = cmdfile.ReadLine crt.Screen.Send line2 & Chr(13) crt.Screen.waitForString "#" loop crt.Screen.Send "show running-config" & chr(13) crt.Screen.WaitForString "#" '打开more提示 crt.Screen.Send "more on" & chr(13) crt.Screen.WaitForString "#" crt.Screen.Send "exit" & chr(13) crt.Screen.WaitForString ">" crt.Session.Disconnect end if if mode = "c" then 'c 代表思科型号 crt.Screen.WaitForString ">" crt.Screen.Send "enable" & chr(13) crt.Screen.WaitForString "assword:" crt.Screen.Send params(3) & chr(13) crt.Screen.WaitForString "#" '关闭more提示 crt.Screen.Send "configure terminal" & chr(13) crt.Screen.WaitForString "config)#" crt.Screen.Send "line vty 0 4" & chr(13) crt.Screen.WaitForString "line)#" crt.Screen.Send "length 0" & chr(13) crt.Screen.WaitForString "line)#" crt.Screen.Send "end" & chr(13) crt.Screen.WaitForString "#" '执行命令集 Set cmdfile = fso.OpenTextFile("D:\backup\cmd-cisco.txt",Forreading, False) do while cmdfile.AtEndOfStream True line2 = cmdfile.ReadLine crt.Screen.Send line2 & Chr(13) crt.Screen.waitForString "#" loop crt.Screen.Send "show running-config" & chr(13) crt.Screen.WaitForString "#" '打开more提示 crt.Screen.Send "configure terminal" & chr(13) crt.Screen.WaitForString "config)#" crt.Screen.Send "line vty 0 4" & chr(13) crt.Screen.WaitForString "line)#" crt.Screen.Send "no length" & chr(13) crt.Screen.WaitForString "line)#" crt.Screen.Send "end" & chr(13) crt.Screen.WaitForString "#" crt.Session.Disconnect end if if mode = "r" then 'r 代表锐捷型号 crt.Screen.WaitForString ">" crt.Screen.Send "enable" & chr(13) crt.Screen.WaitForString "assword:" crt.Screen.Send params(3) & chr(13) crt.Screen.WaitForString "#" '关闭more提示 crt.Screen.Send "configure terminal" & chr(13) crt.Screen.WaitForString "config)#" crt.Screen.Send "line vty 0 15" & chr(13) crt.Screen.WaitForString "line)#" crt.Screen.Send "length 0" & chr(13) crt.Screen.WaitForString "line)#" crt.Screen.Send "end" & chr(13) crt.Screen.WaitForString "#" '执行命令集 Set cmdfile = fso.OpenTextFile("D:\backup\cmd-rj.txt",Forreading, False) do while cmdfile.AtEndOfStream True line2 = cmdfile.ReadLine crt.Screen.Send line2 & Chr(13) crt.Screen.waitForString "#" loop crt.Screen.Send "show running-config" & chr(13) crt.Screen.WaitForString "#" '打开more提示 crt.Screen.Send "configure terminal" & chr(13) crt.Screen.WaitForString "config)#" crt.Screen.Send "line vty 0 15" & chr(13) crt.Screen.WaitForString "line)#" crt.Screen.Send "no length" & chr(13) crt.Screen.WaitForString "line)#" crt.Screen.Send "end" & chr(13) crt.Screen.WaitForString "#" crt.Session.Disconnect end if if mode = "z" then 'z 代表兴型号 crt.Screen.Send "enable" & chr(13) crt.Screen.WaitForString "assword:" crt.Screen.Send params(3) & chr(13) crt.Screen.WaitForString "#" '执行命令集 Set cmdfile = fso.OpenTextFile("D:\backup\cmd-zx.txt",Forreading, False) do while cmdfile.AtEndOfStream True line2 = cmdfile.ReadLine crt.Screen.Send line2 & Chr(13) if (crt.Screen.WaitForString (" --More--",1)False) then crt.Screen.Send " " & chr(13) else crt.Screen.Send chr(13) end if crt.Screen.waitForString "#" loop 'crt.Screen.Send "show running-config" & chr(13) 'crt.Screen.WaitForString " --More--" 'crt.Screen.WaitForString "#" crt.Session.Disconnect
第一个文件ajax_txt.asp的代码: (此页是AJAX异步提交txt文本文件的路径到ajax_txt_save.asp页面,并从ajax_txt_save.asp获取返回的数据) 无标题文档 <script type="text/javascript">

JS读取文本文件的内容并赋值给textarea控件



<textarea id="textarea1" name="textarea1" cols="46" rows="20">textarea>

已导入:0 条记录


第二个文件ajax_txt_save.asp的代码: (此页是用ASP的FSO来读取txt文本文件的内容并输出,为ajax_txt.asp这个页面的AJAX异步获取提供数据) <% '//禁止缓存该页 让AJAX读取该页始终为最新而非过期缓存页 Response.Expires = 0 Response.Expiresabsolute = Now() - 1 Response.AddHeader "pragma","no-cache" Response.AddHeader "cache-control","private" Response.CacheControl = "no-cache" response.Charset="GB2312" '//数据返回的编码类型 显示文数据必须 Dim objFSO Dim objText Dim ObjFile Dim strTextContent Dim objDrive '创建一个文件操作对象实例 Set objFSO = CreateObject("Scripting.FileSystemObject") '要打开的文件 ObjFile=trim(request("filesname")) '从文浏览控件获取 IF objFSO.FileExists(ObjFile) then Set objText = objFSO.OpenTextFile(ObjFile,1) '循环读取数据 k=0 While not objText.AtEndOfStream '到文件的末尾 strTextContent = strTextContent & objText.ReadLine() & vbcrlf k=k+1 wend objText.Close response.write strTextContent & "," & k else strTextContent= "文件不存在" response.end() end if %> 以上代码经测试,100%能使用,且不受浏览器的安全级别限制,祝你好运!

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧