#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    8
    Rep Power
    0

    Replace escape characters


    Folks,
    I am needing to replace ALL escape characters generated.
    the people at my work decided to name files with escape characters and it is driving the code nuts. I started to account for this but it is getting out of hand and causing problems. I used the REPLACE code but it keeps getting longer and longer, I need one script to replace all escape characters with orginal characters.



    Code:
    <%  
    ' retrive base directory 
    dim BaseFileDir:BaseFileDir= Request.Form("dir")
    ' if blank give default value if len(BaseFileDir)=0 then BaseFileDir="/"  
    dim ObjFSO,BaseFile,Html 
    ' resolve the absolute path
     BaseFile = "//pathtofileslocatedhere" & (Replace(Replace(Replace(BaseFileDir, "%20", " " ), "%25", ""), "20", " "))
     ' create FSO 
    Set ObjFSO = Server.CreateObject("Scripting.FileSystemObject")
     ' if given folder is exists
     if ObjFSO.FolderExists(BaseFile) then        
    dim ObjFolder,ObjSubFolder,ObjFile,i__Name,i__Ext       
     Html = Html +  "<ul class=""jqueryFileTree"" style=""display: none;"">"&VBCRLF        
    Set ObjFolder = ObjFSO.GetFolder(BaseFile)       
     ' LOOP THROUGH SUBFOLDER        
    For Each ObjSubFolder In ObjFolder.SubFolders                i__Name=ObjSubFolder.name                
    Html = Html + "<li class=""directory collapsed"">"&_
                                              "<a href=""#"" rel="""+(BaseFileDir+i__Name+"/")+""">"&_
                                              (i__Name)+"</a></li>"&VBCRLF
            Next
            'LOOP THROUGH FILES
            For Each ObjFile In ObjFolder.Files
                    ' name
                    i__Name=ObjFile.name
                    ' extension
                    i__Ext = LCase(Mid(i__Name, InStrRev(i__Name, ".", -1, 1) + 1))
                    Html = Html + "<li class=""file ext_"&i__Ext&""">"&_ 
                                             "<a href=""#"" rel="""+(BaseFile+i__Name)+""">"&_
                                              (i__name)+"</a></li>"&VBCRLF
            Next
            Html = Html +  "</ul>"&VBCRLF
     end if
      Response.Write Html %>

    GREALTY appreciated,
    Plasmagrid
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,436
    Rep Power
    4539
    Google found that if you were using NET you could use the HttpServerUrldecode() function. I don't know if anything similar exists for classic asp.

    http://msdn.microsoft.com/en-us/library/6196h3wt.aspx
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    8
    Rep Power
    0
    Originally Posted by Doug G
    Google found that if you were using NET you could use the HttpServerUrldecode() function. I don't know if anything similar exists for classic asp.

    http://msdn.microsoft.com/en-us/library/6196h3wt.aspx
    that was my issue too. i searched google. and unfortunatly my admins are too cheap to upgrade the server to .NET. it's an old server they say and do not want to add any more "enhancements"
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    8
    Rep Power
    0

    The Fix


    Originally Posted by plasmagrid
    that was my issue too. i searched google. and unfortunatly my admins are too cheap to upgrade the server to .NET. it's an old server they say and do not want to add any more "enhancements"
    For those of you interested, I found this fix and sub'd it in the code

    Code:
    <% 
        Function URLDecode(str) 
            str = Replace(str, "+", " ") 
            For i = 1 To Len(str) 
                sT = Mid(str, i, 1) 
                If sT = "%" Then 
                    If i+2 < Len(str) Then 
                        sR = sR & _ 
                            Chr(CLng("&H" & Mid(str, i+1, 2))) 
                        i = i+2 
                    End If 
                Else 
                    sR = sR & sT 
                End If 
            Next 
            URLDecode = sR 
        End Function 
     
        Function URLEncode(str) 
            URLEncode = Server.URLEncode(str) 
        End Function 
     
       
    %>

    I made a two line changes


    Code:
    <%
    
    ' retrive base directory
    dim BaseFileDir:BaseFileDir= URLDecode(Request.Form("dir"))
    ' if blank give default value
    if len(BaseFileDir)=0 then BaseFileDir="/"
    
    dim ObjFSO,BaseFile,Html
    ' resolve the absolute path
    'BaseFile = "location of files" & (Replace(Replace(Replace(BaseFileDir, "%20", " " ), "%25", ""), "20", " "))
    BaseFile = "location of files" & BaseFileDir
    
    
    
    ' create FSO
    Set ObjFSO = Server.CreateObject("Scripting.FileSystemObject")
    ' if given folder is exists
    if ObjFSO.FolderExists(BaseFile) then
           dim ObjFolder,ObjSubFolder,ObjFile,i__Name,i__Ext
           Html = Html +  "<ul class=""jqueryFileTree"" style=""display: none;"">"&VBCRLF
           Set ObjFolder = ObjFSO.GetFolder(BaseFile)
           ' LOOP THROUGH SUBFOLDER
           For Each ObjSubFolder In ObjFolder.SubFolders
                   i__Name=ObjSubFolder.name
                   Html = Html + "<li class=""directory collapsed"">"&_
                                             "<a href=""#"" rel="""+(BaseFileDir+i__Name+"/")+""">"&_
                                             (i__Name)+"</a></li>"&VBCRLF
           Next
           'LOOP THROUGH FILES
           For Each ObjFile In ObjFolder.Files
                   ' name
                   i__Name=ObjFile.name
                   ' extension
                   i__Ext = LCase(Mid(i__Name, InStrRev(i__Name, ".", -1, 1) + 1))
                   Html = Html + "<li class=""file ext_"&i__Ext&""">"&_
                                             "<a href=""#"" rel="""+(BaseFile+i__Name)+""">"&_
                                             (i__name)+"</a></li>"&VBCRLF
           Next
           Html = Html +  "</ul>"&VBCRLF
    end if
    
    Response.Write Html
    
    %>
  8. #5
  9. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,436
    Rep Power
    4539
    Thank you for posting your solution
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester

IMN logo majestic logo threadwatch logo seochat tools logo