尝试使用循环检查图像是否存在,但是始终返回false。我确定我正在做一些简单而愚蠢的事情,但这是代码:
dim fs, sql_except
set fs=Server.CreateObject("Scripting.FileSystemObject")
if Not rs.eof then
arrRS = rs.GetRows(30,0)
set rs = nothing
If IsArray(arrRS) Then
For i = LBound(arrRS, 2) to UBound(arrRS, 2)
sku = arrRS(0, i)
if (fs.FileExists("../i/"&sku&".gif")=false) Then
response.write sku&"does not exist<br>"
end if
next
end if
erase arrRS
end if
set fs=nothing
最佳答案
您似乎在印象中,您对FileExists
的调用将假定当前文件夹上下文是包含要执行的ASP脚本的物理文件夹。事实并非如此,很可能是“ C:\ windows \ system32 \ inetsrv”。您还使用URL路径元素分隔符/
,其中FileExists期望Windows物理路径文件夹分隔符\
。
您需要使用Server.MapPath
来解析路径。这可能起作用:
if Not fs.FileExists(Server.MapPath("../i/"&sku&".gif")) then
但是,您可能会遇到父路径“ ..”的麻烦,出于安全原因,可能不允许这样做。这可能是一个更好的方法:
Dim path : path = Server.MapPath("/parentFolder/i") & "\"
For i = LBound(arrRS, 2) to UBound(arrRS, 2)
sku = arrRS(0, i)
if Not fs.FileExists(path & sku & ".gif") Then
response.write Server.HTMLEncode(sku) & " does not exist<br>"
end if
next
其中“ parentFolder”是从站点根目录开始的绝对路径。
关于asp-classic - asp fileExists总是返回false,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10236687/