100分求救.

oubao 2004-12-09 09:56:58
sqlf = "select * from username"
Set fso = CreateObject("scripting.FileSystemObject")
Set tf = fso.CreateTextFile("c:\"a".txt", True)
tf.Write sqlf

我用这个段代码保存成a文件,但我想在a文件已经存在条件下则保存成a1文件,a1文件存在条件下保存成a2文件,请问该怎么办?

同样的,在打开文件时我想先把有关a的文件如a1,a2等文件的名字一起列出来,然后选取任意一个后再打开该文件,该怎么写?

谢谢指教!急,请大家帮忙!
...全文
102 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
oubao 2004-12-09
  • 打赏
  • 举报
回复
万分感谢!!!
pennyclz 2004-12-09
  • 打赏
  • 举报
回复
up
itcoo 2004-12-09
  • 打赏
  • 举报
回复
人才啊~~,做业务员一定满足客户各种要求的。
dh20156 2004-12-09
  • 打赏
  • 举报
回复
现在回帖真难啊,都回一送多~~ -_-!!!
lienzhu 2004-12-09
  • 打赏
  • 举报
回复

'.........文件存取部分.................................
sqlf = "select * from username"
Set fso = CreateObject("scripting.FileSystemObject")
i=1
FileName="c:\a.txt"
do while fso.FileExists(FileName)
FileName="c:\a" & i &".txt"
i=i+1
loop
Set tf = fso.CreateTextFile(FileName, True)
tf.Write sqlf
'........文件列表部分.....................................
<%
function getfile(filename)
tmp=lcase(filename)
if len(tmp)<5 then
getfile=false
elseif Left(tmp,1)<>"a" or right(tmp,4)<>".txt" then
getfile=false
else
getfile=true
end if
end function
set fso = server.createobject("scripting.filesystemobject")'定义文件系统对象
set fd = fso.getfolder("c:\") '定义文件夹对象
For Each file in fd.Files
if getfile(file.name) then
response.write "<a href='open.asp?fname="& file.name &"'>" & file.name & "</a><br>"
end if
next
set fd=nothing
set fso=nothing
%>
'...................文件读取部分..............................
open.asp
---------------------------
<%
Filename="c:\" & trim(request.querystring("fname"))
set fso = server.createobject("scripting.filesystemobject")'定义文件系统对象
if fso.FileExists(Filename) then
set mytext=fso.opentextfile(Filename)
temp=mytext.readall
mytext.close
set mytext=nothing
end if
set fso=nothing
response.write "<pre>"& temp &"<pre>"
%>
lienzhu 2004-12-09
  • 打赏
  • 举报
回复
open.asp
---------------------------
<%
Filename="c:\" & trim(request.querystring("fname"))
set fso = server.createobject("scripting.filesystemobject")'定义文件系统对象
if fso.FileExists(Filename) then
set mytext=fso.opentextfile(Filename)
temp=mytext.readall
mytext.close
set mytext=nothing
end if
set fso=nothing
response.write "<pre>"& temp &"<pre>"
%>
lienzhu 2004-12-09
  • 打赏
  • 举报
回复
<%
function getfile(filename)
tmp=lcase(filename)
if len(tmp)<5 then
getfile=false
elseif Left(tmp,1)<>"a" or right(tmp,4)<>".txt" then
getfile=false
else
getfile=true
end if
end function
set fso = server.createobject("scripting.filesystemobject")'定义文件系统对象
set fd = fso.getfolder("d:\main") '定义文件夹对象
For Each file in fd.Files
if getfile(file.name) then
response.write "<a href='open.asp?fname="& file.name &"'>" & file.name & "</a><br>"
end if
next
set fd=nothing
set fso=nothing
%>
oubao 2004-12-09
  • 打赏
  • 举报
回复
谢谢二位的指点。
suntoday 2004-12-09
  • 打赏
  • 举报
回复
帮你顶一下,
micher_yan 2004-12-09
  • 打赏
  • 举报
回复
'检测指定路径或文件是否存在
function Test_FilePath(ByVal filepath)
Test_FilePath=false
filepath=server.MapPath(filepath)
dim fso
set fso=Server.CreateObject("Scripting.FileSystemObject")
if right(filepath,1)="/" or right(filepath,1)="\" then
if fso.FolderExists(filepath) then
Test_FilePath=true
end if
else
if fso.FileExists(filepath) then
Test_FilePath=true
end if
end if
set fso=nothing
end function
'保存内容到指定文件
sub SaveValueTofile(byref FileValue,byref filename)
dim fso
set fso=Server.CreateObject("Scripting.FileSystemObject")
dim f
set f=fso.CreateTextFile(Server.MapPath(filename),true)
f.Write FileValue
set f=nothing
set fso=nothing
end sub
使用
for i=1 to 999
if not test_filepath("a"&i&".txt") then
savevaluetofile(sqlf,"a"&i&".txt")
exit for
end if
next
lienzhu 2004-12-09
  • 打赏
  • 举报
回复
sqlf = "select * from username"
Set fso = CreateObject("scripting.FileSystemObject")
i=1
FileName="c:\a.txt"
do while fso.FileExists(FileName)
FileName="c:\a" & i &".txt"
i=i+1
loop
Set tf = fso.CreateTextFile(FileName, True)
tf.Write sqlf

28,409

社区成员

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

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