用asp整理磁盤文件
發(fā)布時(shí)間:2008-10-05 閱讀數(shù): 次 來(lái)源:網(wǎng)樂(lè)原科技
機(jī)器的文件太多,需要整理一下,該如何做呢?????
本文以整理圖片文件為例,給大家一點(diǎn)思路
代碼的運(yùn)行環(huán)境:iis5.0+sql server2000
數(shù)據(jù)庫(kù)腳本:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[insertpic]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[insertpic]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[showpage]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[showpage]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[picpath]') and OBJECTPROPERTY(id, N'IsUserTable') = 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
/*
'# 過(guò)程:showpage
'# 描述:用來(lái)記錄集分頁(yè)
'# 參數(shù): - pagenum (頁(yè)碼)
'# 返回:-兩個(gè)記錄集,第一個(gè)記錄集包含兩個(gè)字段(總頁(yè)數(shù)),第二個(gè)記錄集為數(shù)據(jù)庫(kù)返回給程序要顯示的數(shù)據(jù)
'# 作者:zhengs
'# 日期:2002-08-27
*/
CREATE PROCEDURE showpage
----頁(yè)碼
@PageNum int
AS
SET NOCOUNT ON
declare
@pagecount int,
@iFrom int,
@iRowCount int,
@dpicid int
----計(jì)算該頁(yè)起始的偏移量
if @PageNum <= 0
set @PageNum = 1
set @iFrom = 10 * (@PageNum - 1) + 1
----判斷傳入的頁(yè)碼是否有效
select @iRowCount = count(id) from picpath ----取得圖片數(shù)
set @PageCount = @iRowCount / 10 ----計(jì)算圖片頁(yè)數(shù)
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
搜索并存儲(chǔ)到數(shù)據(jù)庫(kù)
search.asp
<%@LANGUAGE="VBSCRIPT" %>
<%
'***********************************************************************************
' 文件名.........: search.asp
' 作者...........: cxb
' 說(shuō)明...........: 搜索并存儲(chǔ)到數(shù)據(jù)庫(kù)
' 注意...........:
' 版權(quán)...........: Copyright (c) 2000, NetDragon Software.
' 修改記錄.......: 時(shí)間 人員 備注
' --------- ------- -------------------------------------------
' 2003-09-26 陳興柏 創(chuàng)建文件
'***********************************************************************************
Server.ScriptTimeOut=500
dim a,b
'檢測(cè)時(shí)間參數(shù)
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
'# --------------------------------------------------------------------------
'# 函數(shù):getFileExtName
'# 描述:獲得文件是否為圖片文件
'# 參數(shù):--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
'# --------------------------------------------------------------------------
'# 函數(shù):insertfilepath
'# 描述:將路徑信息插入數(shù)據(jù)庫(kù)
'# 參數(shù):--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
'# --------------------------------------------------------------------------
'# 函數(shù):ShowFiles
'# 描述:搜索文件夾和文件
'# 參數(shù):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) '存儲(chǔ)到數(shù)據(jù)庫(kù)
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 '程序結(jié)束時(shí)間
response.Write("共運(yùn)行"&b-a&"秒")
'搜索并存儲(chǔ)
end if
set conn=nothing
%><title>搜索并存儲(chǔ)到數(shù)據(jù)庫(kù)</title>
<div align="center"><a href=search.asp?action=search>搜索并存儲(chǔ)到數(shù)據(jù)庫(kù)</a></div>
整理頁(yè)面
show.asp
<%@LANGUAGE="VBSCRIPT" %>
<%
'***********************************************************************************
' 文件名.........: show.asp
' 作者...........: cxb
' 說(shuō)明...........:
' 注意...........:
' 版權(quán)...........: Copyright (c) 2000, NetDragon Software.
' 修改記錄.......: 時(shí)間 人員 備注
' --------- ------- -------------------------------------------
' 2003-09-26 陳興柏 創(chuàng)建文件
'***********************************************************************************
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) '顯示頁(yè)面
conn.close
set conn=nothing
'# ----------------------------------------------------------------------------
'# 函數(shù):delwl(id)
'# 描述:完成刪除物理圖片
'# 參數(shù):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
'以上完成刪除物理圖片
'以下完成刪除數(shù)據(jù)庫(kù)的圖片信息
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('已經(jīng)成功刪除物理圖片!');window.location='show.asp?page="&page&"';</script>"
end if
end function
'# ----------------------------------------------------------------------------
'# 函數(shù):createpic
'# 描述:生成圖片信息并分頁(yè)
'# 參數(shù):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
'傳遞頁(yè)數(shù)
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'>對(duì)不起!暫時(shí)沒(méi)有信息!</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=點(diǎn)擊這里查看原圖></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>第一頁(yè)</a>"
strTemp=strTemp&"<a href=show.asp?page="&cint(page-1)&">上一頁(yè)</a>"
end if
if page<>yeshu and yeshu>=1 then
strTemp=strTemp&"<a href=show.asp?page="&cint(page+1)&">下一頁(yè)</a>"
strTemp=strTemp&"<a href=show.asp?page="&yeshu&">最后一頁(yè)</a>"
end if
if yeshu>=1 then
strTemp=" "&strTemp&page&"/"&yeshu&"頁(yè)"
end if
if yeshu>=2 then '如果頁(yè)數(shù)大于1就建立跳轉(zhuǎn)
strTemp=strTemp& " 第"&"<input name='page' type='text' id='page' size='2'>"&"頁(yè) <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="點(diǎn)擊關(guān)閉"></a>
</body>
</html>
完成!
當(dāng)然你可以根據(jù)需要 增加或刪除一些咚咚!