ASP deleting unrecorded pictures requires a double loop to compare each picture in the folder (the folder where the pictures are stored) with all records in the database. Divide the picture and ask the first part of the name, then compare it with the picture path records in the remaining database.
If the InStr function of vb exists, the return value is >0, and you can draw a conclusion.
The code is as follows deal.asp
Copy the code code as follows:
<%@ language=vbscript%>
<%response.Expires = 0%>
<!--#include file=conn.asp-->
<%
Dim objFSO,objFolder,objFile,FF 'Declare objFSO variable to store object instance
FF = Server.MapPath(pro_s/)
Set objFSO = Server.CreateObject(Scripting.FileSystemObject)
If objFSO.FolderExists(ff) Then
Response.write All files in folder &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 folder &ff& does not exist and related information cannot be read!
End If
Set objFolder = Nothing
Set objFSO = Nothing 'Release FileSystemObject object instance memory space
%>