欢迎光临
我们一直在努力

用asp整理磁盘文件-ASP教程,ASP应用

建站超值云服务器,限时71元/月

机器的文件太多,需要整理一下,该如何做呢?????

本文以整理图片文件为例,给大家一点思路

代码的运行环境:iis5.0+sql server2000

数据库脚本:

if exists (select * from dbo.sysobjects where id = object_id(n[dbo].[insertpic]) and objectproperty(id, nisprocedure) = 1)

drop procedure [dbo].[insertpic]

go

if exists (select * from dbo.sysobjects where id = object_id(n[dbo].[showpage]) and objectproperty(id, nisprocedure) = 1)

drop procedure [dbo].[showpage]

go

if exists (select * from dbo.sysobjects where id = object_id(n[dbo].[picpath]) and objectproperty(id, nisusertable) = 1)

drop table [dbo].[picpath]

go

create table [dbo].[picpath] (

[id] [int] identity (1, 1) not null ,

[path] [varchar] (100) collate chinese_prc_ci_as null

) on [primary]

go

set quoted_identifier off

go

set ansi_nulls off

go

–作用:插入记录

create procedure [insertpic]

(

–路径–

@path varchar(100)

)

as

insert picpath(path) values(@path)

go

set quoted_identifier off

go

set ansi_nulls on

go

set quoted_identifier off

go

set ansi_nulls off

go

/*

# 过程:showpage

# 描述:用来记录集分页

# 参数: – pagenum (页码)

# 返回:-两个记录集,第一个记录集包含两个字段(总页数),第二个记录集为数据库返回给程序要显示的数据

# 作者:zhengs

# 日期:2002-08-27

*/

create procedure showpage

—-页码

@pagenum int

as

set nocount on

declare

@pagecount int,

@ifrom int,

@irowcount int,

@dpicid int

—-计算该页起始的偏移量

if @pagenum <= 0

set @pagenum = 1

set @ifrom = 10 * (@pagenum – 1) + 1

—-判断传入的页码是否有效

select @irowcount = count(id) from picpath —-取得图片数

set @pagecount = @irowcount / 10 —-计算图片页数

if @irowcount %10> 0

set @pagecount = @pagecount + 1

if @irowcount < @ifrom

begin

set @ifrom = @irowcount – 10

end

if @ifrom<0

select @ifrom=0

set rowcount @ifrom

select @dpicid = id from picpath order by id desc

set rowcount 0

—-取得图片列表

select @pagecount as pagecount

select top 10 * from picpath where id <= @dpicid order by id desc

set nocount off

sp_end:

select @pagecount as pagecount

set nocount off

go

set quoted_identifier off

go

set ansi_nulls on

go

搜索并存储到数据库

search.asp

<%@language="vbscript" %>

<%

***********************************************************************************

文件名………: search.asp

作者………..: cxb

说明………..: 搜索并存储到数据库

注意………..:

版权………..: copyright (c) 2000, netdragon software.

修改记录…….: 时间 人员 备注

——— ——- ——————————————-

2003-09-26 陈兴柏 创建文件

***********************************************************************************

server.scripttimeout=500

dim a,b

检测时间参数

a=timer

dim conn,strconn

set conn = server.createobject("adodb.connection")

strconn = "provider=sqloledb;data source=127.0.0.1;initial catalog=search;user id=sa;password=196881"

conn.open strconn

const adcmdstoredproc = &h0004

const adparaminput = &h0001

const advarchar = 200

# ————————————————————————–

# 函数:getfileextname

# 描述:获得文件是否为图片文件

# 参数:–fname

# 返回:–true or false

# 作者:cxb

# 日期:2003-9-26

#————————————————————————–

function getfileextname(fname)

if instr(fname,".gif") or instr(fname,".gif") or instr(fname,".jpg") or instr(fname,".jpg") or instr(fname,".bmp") or instr(fname,".bmp") then

getfileextname=true

else

getfileextname=false

end if

end function

# ————————————————————————–

# 函数:insertfilepath

# 描述:将路径信息插入数据库

# 参数:–filename

# 返回:–

# 作者:cxb

# 日期:2003-9-26

#————————————————————————–

function insertfilepath(filename)

dim piccommand,filepath

set piccommand=server.createobject("adodb.command")

set piccommand.activeconnection=conn

piccommand.commandtype=adcmdstoredproc

piccommand.commandtext="insertpic"

set filepath=piccommand.createparameter("path",advarchar,adparaminput,100)

piccommand.parameters.append filepath

piccommand("path")=filename

piccommand.execute

set piccommand=nothing

end function

# ————————————————————————–

# 函数:showfiles

# 描述:搜索文件夹和文件

# 参数:objfolder

# 作者:cxb

# 返回:所有的文件名和所在的目录

# 日期:2003-9-26

#————————————————————————–

function showfiles(byref objfolder)

dim folder,filename

递归获得所有的文件

for each folder in objfolder.subfolders

showfiles folder

next

for each filename in objfolder.files 搜索所有的文件

if getfileextname(filename.name) then 检查是否为图片

insertfilepath(filename) 存储到数据库

end if

next

end function

dim objfolder,objrootfolder

set objfolder=server.createobject("scripting.filesystemobject")

set objrootfolder=objfolder.getfolder("c:\inetpub\wwwroot\zy")

这里的路径可以改变

if request.querystring("action")="search" then

showfiles objrootfolder

b=timer 程序结束时间

response.write("共运行"&b-a&"秒")

搜索并存储

end if

set conn=nothing

%><title>搜索并存储到数据库</title>

<div align="center"><a href=search.asp?action=search>搜索并存储到数据库</a></div>

整理页面

show.asp

<%@language="vbscript" %>

<%

***********************************************************************************

文件名………: show.asp

作者………..: cxb

说明………..:

注意………..:

版权………..: copyright (c) 2000, netdragon software.

修改记录…….: 时间 人员 备注

——— ——- ——————————————-

2003-09-26 陈兴柏 创建文件

***********************************************************************************

server.scripttimeout=100

dim conn,strconn

set conn = server.createobject("adodb.connection")

strconn = "provider=sqloledb;data source=192.168.1.221;initial catalog=search;user id=sa;password=196881"

conn.open strconn

const adcmdstoredproc = &h0004

const adparaminput = &h0001

const adinteger = 3

page=replace(request("page"),"","")

if page="" then page=1

page=clng(page)

if request("action")="wl" then

完成删除物理图片

delwl(request("checkbox"))

end if

dim news

pic=createpic(page) 显示页面

conn.close

set conn=nothing

# —————————————————————————-

# 函数:delwl(id)

# 描述:完成删除物理图片

# 参数:id

# 返回:–

# 作者:陈兴柏

# 日期:2003.09.26

#—————————————————————————–

function delwl(id)

if id <>"" then

dim fso,skyfile,rs,sql ,adocmd_del

set fso = createobject("scripting.filesystemobject")

set rs= server.createobject("adodb.recordset")

sql="select path from picpath where id in "

sql=sql &"(" & id & ")"

rs.open sql,conn,1,3

while not rs.eof

if fso.fileexists (rs(0)) then

set skyfile = fso.getfile(rs(0))

skyfile.delete()

end if

rs.movenext

wend

set rs=nothing

set fso=nothing

以上完成删除物理图片

以下完成删除数据库的图片信息

sql="delete from picpath where id in "

sql=sql &"(" & id & ")"

set adocmd_del = server.createobject("adodb.command")

adocmd_del.activeconnection = conn

adocmd_del.commandtext = sql

adocmd_del.execute()

set adocmd_del=nothing

response.write "<script>alert(已经成功删除物理图片!);window.location=show.asp?page="&page&";</script>"

end if

end function

# —————————————————————————-

# 函数:createpic

# 描述:生成图片信息并分页

# 参数:page

# 返回:–

# 作者:陈兴柏

# 日期:2003.09.26

#—————————————————————————–

function createpic(page)

dim piccommand,yeshu,strtemp,tp,id

set piccommand=server.createobject("adodb.command")

set piccommand.activeconnection=conn

piccommand.commandtype=adcmdstoredproc

piccommand.commandtext="showpage"

set pagenum=piccommand.createparameter("@pagenum",adinteger,adparaminput)

piccommand.parameters.append pagenum

传递页数

piccommand("@pagenum")=clng(page)

set rs=piccommand.execute

yeshu=rs("pagecount")

set rs=rs.nextrecordset

strtemp=""

strtemp="<form method=post><table width=100% style=border-collapse: collapse; border: 1 solid #669ed6 cellspacing=0 cellpadding=2>"

if rs.eof then

strtemp=strtemp&"<tr><td><font color=#ff0000>对不起!暂时没有信息!</font></tr></td>"

strtemp=strtemp&"</table>"

else

strtemp = strtemp &"<tr><td style=border: 1 solid #669ed6 align=center><input type=button value=全选 onclick=this.value=check(this.form.checkbox)></td><td style=border: 1 solid #669ed6 bgcolor=#999999 align=center><font size=3><font face=黑体>路径</font></font></td><td style=border: 1 solid #669ed6 bgcolor=#999999 align=center> <font size=3><font face=黑体>图片</font></font></td></tr>"

do while (not rs.eof)

id=rs(0)

tp=rs(1)

strtemp = strtemp &"<tr><td style=border: 1 solid #669ed6 align=center><input type=checkbox name=checkbox value="&id&"></td><td style=border: 1 solid #669ed6>"&tp&"</td><td style=border: 1 solid #669ed6><a href=showdetail.asp?tp="&tp&" target=_blank><img src="&tp&" width=100 height=50 border=0 alt=点击这里查看原图></a></td></tr>"

rs.movenext

loop

strtemp=strtemp&"</table>"

strtemp=strtemp&"<table width=500 border=0 cellspacing=0 cellpadding=0> <tr><td><input type=submit name=submit value=删除选中物理图片 onclick=this.form.action=show.asp?action=wl&page="&page&"></td></tr></table></form>"

strtemp=strtemp&"<br><table width=100% ><form name=form1 action=show.asp><tr><td align=right>"

if page<>1 and yeshu>=1 then

strtemp=strtemp&"<a href=show.asp?page=1>第一页</a>"

strtemp=strtemp&"<a href=show.asp?page="&cint(page-1)&">上一页</a>"

end if

if page<>yeshu and yeshu>=1 then

strtemp=strtemp&"<a href=show.asp?page="&cint(page+1)&">下一页</a>"

strtemp=strtemp&"<a href=show.asp?page="&yeshu&">最后一页</a>"

end if

if yeshu>=1 then

strtemp=" "&strtemp&page&"/"&yeshu&"页"

end if

if yeshu>=2 then 如果页数大于1就建立跳转

strtemp=strtemp& " 第"&"<input name=page type=text id=page size=2>"&"页 <a href=# onclick=document.form1.submit();>go</a>"

end if

strtemp=strtemp&"</tr></td></form ></table>"

end if

createpic=strtemp

rs.close

set rs=nothing

set piccommand=nothing

end function

%>

<!doctype html public "-//w3c//dtd html 4.01 transitional//en">

<html>

<head>

<style>

a {

font-size: 12px;

text-decoration: none;

font-family: "arial", "helvetica", "sans-serif";

line-height: 20px;

; color: #000000

}

a:active { font-size: 12px; color: #000000; text-decoration: none; font-family: "arial", "helvetica", "sans-serif"}

a:hover { font-size: 12px; color: #ff6600; font-family: "arial", "helvetica", "sans-serif"; text-decoration: none}

.white {

font-family: "arial", "helvetica", "sans-serif";

font-size: 12px;

line-height: 20px;

color: #ffffff;

text-decoration: none;

}</style>

<meta http-equiv="content-type" content="text/html; charset=gb2312">

<title>显示图片</title>

</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<div align="center">

<table width="650" height="18" border="0" cellpadding="0" cellspacing="0">

<tr>

<td ><%=pic%></td>

</tr>

</table>

</div>

<script language="javascript">

<!– begin

var checkflag = "false";

function check(field) {

if (checkflag == "false") {

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

field[i].checked = true;}

checkflag = "true";

return "全不选"; }

else {

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

field[i].checked = false; }

checkflag = "false";

return "全选"; }

}

// end –>

</script>

</body>

</html>

showdetail.asp

<!doctype html public "-//w3c//dtd html 4.01 transitional//en">

<html>

<head>

<meta http-equiv="content-type" content="text/html; charset=gb2312">

<title>显示图片</title>

</head>

<body>

<a href="#" onclick="javascript:window.close();"><img src="<%=request.querystring("tp")%>" border="0" alt="点击关闭"></a>

</body>

</html>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 用asp整理磁盘文件-ASP教程,ASP应用
分享到: 更多 (0)