asp刪除mssql數(shù)據(jù)庫中沒有記錄的圖片代碼
更新時間:2009年08月30日 20:54:28 作者:
asp刪除沒有記錄的圖片需要文件夾(存放圖片的文件夾)中的每個圖片和數(shù)據(jù)庫中的所有記錄進行比較
采用雙重循環(huán)。把圖片進行“.”分割后名字問前面部分,那其余數(shù)據(jù)庫中的 圖片路徑記錄進行對比
采用vb的InStr函數(shù) 如果存在的話返回值>0,過可以得出結(jié)論
代碼如下deal.asp
<%@ language="vbscript"%>
<%response.Expires = 0%>
<!--#include file="conn.asp"-->
<%
Dim objFSO,objFolder,objFile,FF '聲明 objFSO 變量存放對象實例
FF = Server.MapPath("pro_s/")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(ff) Then
Response.write "文件夾 "&ff&" 里所有的文件:<br>"
Set objFolder = objFSO.GetFolder(ff)
For Each objFile in objFolder.Files
%>
<%
filename=cstr(objFile.name)
myname=split(filename,".")
ffname=myname(0)
a=0
set sclass=conn.execute("select img from wksc_pro ")
do while not sclass.eof
result=Instr(sclass("img"),ffname)
a=a+result
if(a>0) then
exit do
end if
sclass.movenext
loop
if(a=0) then
response.Write ""&objFile&""
response.Write"<br>"
objFile.delete
end if
%>
<%
Next
Else
Response.Write "文件夾"&ff&"不存在,無法讀取相關(guān)信息!"
End If
Set objFolder = Nothing
Set objFSO = Nothing '釋放 FileSystemObject 對象實例內(nèi)存空間
%>
來自:http://blog.csdn.net/lingfeng179/archive/2009/08/19/4463679.aspx
采用vb的InStr函數(shù) 如果存在的話返回值>0,過可以得出結(jié)論
代碼如下deal.asp
復制代碼 代碼如下:
<%@ language="vbscript"%>
<%response.Expires = 0%>
<!--#include file="conn.asp"-->
<%
Dim objFSO,objFolder,objFile,FF '聲明 objFSO 變量存放對象實例
FF = Server.MapPath("pro_s/")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(ff) Then
Response.write "文件夾 "&ff&" 里所有的文件:<br>"
Set objFolder = objFSO.GetFolder(ff)
For Each objFile in objFolder.Files
%>
<%
filename=cstr(objFile.name)
myname=split(filename,".")
ffname=myname(0)
a=0
set sclass=conn.execute("select img from wksc_pro ")
do while not sclass.eof
result=Instr(sclass("img"),ffname)
a=a+result
if(a>0) then
exit do
end if
sclass.movenext
loop
if(a=0) then
response.Write ""&objFile&""
response.Write"<br>"
objFile.delete
end if
%>
<%
Next
Else
Response.Write "文件夾"&ff&"不存在,無法讀取相關(guān)信息!"
End If
Set objFolder = Nothing
Set objFSO = Nothing '釋放 FileSystemObject 對象實例內(nèi)存空間
%>
來自:http://blog.csdn.net/lingfeng179/archive/2009/08/19/4463679.aspx
您可能感興趣的文章:
相關(guān)文章
asp中回車換行符CHR(10)表示換行,CHR(13)表示回車,CHR(32)表示空格
這篇文章主要介紹了asp中回車換行符CHR(10)表示換行,CHR(13)表示回車,CHR(32)表示空格,需要的朋友可以參考下2006-08-08ASP計算str2在str1中出現(xiàn)的次數(shù)
可以方便計算一個字符串在另一個字符串出現(xiàn)的次數(shù)2008-05-05