2

ループを使用して画像が存在するかどうかを確認しようとしていますが、常に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
4

1 に答える 1

6

あなたの呼び出しFileExistsが想定する現在のフォルダー コンテキストは、実行中の ASP スクリプトを含む物理フォルダーであるという印象の下で操作しているようです。これはそうではなく、おそらく "C:\windows\system32\inetsrv" になります。/また、FileExists が Windows の物理パス フォルダー セパレーターを想定しているURL パス要素セパレーターを使用しています\

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」は、サイト ルートからの絶対パスです。

于 2012-04-19T21:43:36.270 に答える