Visualizzazione dei risultati da 1 a 8 su 8
  1. #1
    Utente di HTML.it
    Registrato dal
    May 2008
    Messaggi
    488

    mostra file in cartella

    Ciao a tutti, avrei bisogno di aiuto per il seguente problema :
    devo sistemare il seguente codice in modo che mostri i file presenti nelle cartelle sulle quali clicco, partendo da una directory iniziale, ovvero :
    la prima pagina ha il seguente
    codice:
    <%
    Percorso = Trim(LCase(Request.QueryString("percorso")))
    If Percorso = "" then
    Response.redirect "index.asp?percorso=d:\.......FileMan\"
    Else
    If Right(Percorso,1) <> "\" then Percorso = Percorso & "\"
    Mostra_Directory Percorso
    End If    
    Function Mostra_Directory(cartella)
    Set Fso = CreateObject("Scripting.FileSystemObject")
    Set FL = fso.GetFolder(cartella)
    Set SF = fl.SubFolders    
    If Len(cartella) > 60 then
    Precedente = ""
    For f = len(cartella)-1 to 1 step -1
    If Mid(cartella,f,1) = "\" and Precedente = "" then
    Precedente = Mid(cartella,1,f)
    End If
    Next        
    Response.write "<a href='index.asp?percorso=" & Precedente & "' TARGET='_parent'>..torna su di un livello</A><BR>"        
    End If    
    For Each FL in SF
    Sotto_Cartella = FL.Name
    If Len(cartella) < 60 then
    Response.write Sotto_Cartella & "<BR>"
    Else
    Response.write "<a href='index.asp?percorso=" & Percorso & Sotto_Cartella & "' TARGET='_parent'>" & Sotto_Cartella & "</A><BR>"
    end if
    next
    End Function
    %>
    la seconda (che devo sistemare) ha il seguente
    codice:
    <%
    Percorso = Request.QueryString("percorso")
    If Right(Percorso,1) <> "\" then Percorso = Percorso & "\"
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFolder(Percorso)
    Set fc = f.Files
    Numero_File = 0
    FP = ""
    DF = ""
    For Each whatever in fc
    Nome_File = Trim(LCase(whatever.name))
    If Nome_File <> "" Then Numero_File = Numero_File + 1
    Select Case Right(Nome_File,4)
    Case ".txt"
    FP = FP & Nome_File & "<BR>"
    DF = DF & "File di testo<BR>"
    .....    
    End Select
    Next
    %>
    <FONT FACE="Arial" SIZE=2>
    <%If Numero_File = 0 then%>
    Nella directory corrente non sono presenti file.
    <%ElseIf Numero_File = 1 then%>
    E' stato trovato un solo file:<HR>
    <TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0>
    <TR>
    <TD ALIGN=LEFT><FONT FACE="Arial" SIZE=2><%=FP%></FONT></TD>
    <TD ALIGN=LEFT><FONT FACE="Arial" SIZE=2><%=DF%></FONT></TD>
    </TR>
    </TABLE>
    <%Else%>
    Sono stati trovati <%=Numero_File%> File:<HR>
    <TABLE CELLPADDING=4  BORDER=1 WIDTH=100%>
    <tr style="border-bottom-style: solid">
    <td>Nome File</td>
    <td>Tipo</td>
    </tr>
    <TR>
    <TD ALIGN=LEFT><FONT FACE="Arial" SIZE=2><%=FP%></FONT></TD>
    <TD ALIGN=LEFT><FONT FACE="Arial" SIZE=2><%=DF%></FONT></TD>
    </TR>
    </TABLE>
    <%End If%>
    Inizialmente vengono mostrati i file della cartella principale, ma se clicco su altre sottocartelle non venngono mostrati quelli della sottocartella su cui si clicca ma sempre quelli della cartella principale

  2. #2
    Utente di HTML.it
    Registrato dal
    May 2008
    Messaggi
    488
    In pratica, dopo aver mostrato i file della directory principale passata tramite
    codice:
    Percorso = Trim(LCase(Request.QueryString("percorso")))
    come faccio a farmi restituire i file contenuti nelle sottocartelle su cui clicco di volta in volta?
    la pagina file.asp ha il seguente
    codice:
    <%
    Percorso = Request.QueryString("percorso")
    If Right(Percorso,1) <> "\" then Percorso = Percorso & "\"
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFolder(Percorso)
    Set fc = f.Files
    Numero_File = 0
    FP = ""
    DF = ""
    For Each whatever in fc
    Nome_File = Trim(LCase(whatever.name))
    If Nome_File <> "" Then Numero_File = Numero_File + 1
    Select Case Right(Nome_File,4)
    Case ".txt"
    FP = FP & Nome_File & "<BR>"
    DF = DF & "File di testo<BR>"
    .....    
    End Select
    Next
    %>
    <FONT FACE="Arial" SIZE=2>
    <%If Numero_File = 0 then%>
    Nella directory corrente non sono presenti file.
    <%ElseIf Numero_File = 1 then%>
    E' stato trovato un solo file:<HR>
    <TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0>
    <TR>
    <TD ALIGN=LEFT><FONT FACE="Arial" SIZE=2><%=FP%></FONT></TD>
    <TD ALIGN=LEFT><FONT FACE="Arial" SIZE=2><%=DF%></FONT></TD>
    </TR>
    </TABLE>
    <%Else%>
    Sono stati trovati <%=Numero_File%> File:<HR>
    <TABLE CELLPADDING=4  BORDER=1 WIDTH=100%>
    <tr style="border-bottom-style: solid">
    <td>Nome File</td>
    <td>Tipo</td>
    </tr>
    <TR>
    <TD ALIGN=LEFT><FONT FACE="Arial" SIZE=2><%=FP%></FONT></TD>
    <TD ALIGN=LEFT><FONT FACE="Arial" SIZE=2><%=DF%></FONT></TD>
    </TR>
    </TABLE>
    <%End If%>

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2008
    Messaggi
    488
    Qualcuno mi aiuta a capire come mai anche se vedo tutti i file il link è unico ?
    il codice è questo
    codice:
    <%
    Cartella = Trim(LCase(Request.QueryString("cartella")))
    If Right(Cartella,1) <> "\" then Cartella = Cartella & "\"
    %>
    <%
    If Cartella = "" then
        Response.redirect "elencocartelle.asp?percorso=d:.......\FileMan\"
        Else
        If Right(Cartella,1) <> "\" then Cartella = Cartella & "\"
    end if
        %>
    <%
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFolder(Cartella)
    Set fc = f.Files
    %>
    <%
    Numero_File = 0
    FP = ""
    DF = ""
    For Each whatever in fc
        Nome_File = Trim(LCase(whatever.name))
        If Nome_File <> "" Then Numero_File = Numero_File + 1
    
        Select Case Right(Nome_File,4)
    
        Case ".doc"
            FP = FP & Nome_File & "<br>"
            DF = DF & "File di testo<br>"
        Case ".xls"
            FP = FP & Nome_File & "<br>"
            DF = DF & "File di excel<br>"
        Case ".pdf"
            FP = FP & Nome_File & "<BR>"
            DF = DF & "File PDF<BR>"    
        Case ".txt"
            FP = FP & Nome_File & "<BR>"
            DF = DF & "File di testo<BR>"
        Case ".asp"
            FP = FP & Nome_File & "<BR>"
            DF = DF & "File ASP<BR>"
        Case Else
            FP = FP & Nome_File & "<BR>"
            DF = DF & "<BR>"    
        End Select
    Next
    %>
    <%
    Mostra_Directory Cartella
    Function Mostra_Directory(cartella)
        Set Fso = CreateObject("Scripting.FileSystemObject")
        Set FL = fso.GetFolder(cartella)
        Set SF = fl.SubFolders
    If Len(cartella) > 60 then
            Precedente = ""
            For f = len(cartella)-1 to 1 step -1
                If Mid(cartella,f,1) = "\" and Precedente = "" then
                    Precedente = Mid(cartella,1,f)
                End If
            Next
    Response.write "<a name=cartella id=cartella href='elencofile.asp?cartella=" & Precedente & "' TARGET='_parent'>..torna su di un livello</A><BR>"
    End If
    For Each FL in SF
        Sotto_Cartella = FL.Name
        If Len(cartella) < 60 then
            Response.write Sotto_Cartella & "<BR>"
        Else
            Response.write "<a name=cartella id=cartella href='elencofile.asp?cartella=" & Cartella & Sotto_Cartella & "' TARGET='_parent'>" & Sotto_Cartella & "</A><BR>"
    End If
    next
    End Function
    %>
    <%
    Set Fso = CreateObject("Scripting.FileSystemObject")
        Set FL = fso.GetFolder(cartella)
        Set SF = fl.SubFolders
    Sotto_Cartella = FL.Name
    %>
    <FONT FACE="Arial" SIZE=2>
    <%If Numero_File = 0 then%>
    <TABLE CELLPADDING=4  BORDER=1 WIDTH=100%>
        <tr style="border-bottom-style: solid">
        <td colspan="2"><b>Nella directory corrente non sono presenti file.</b></td>
        </tr>
    </TABLE>
    <%ElseIf Numero_File = 1 then%>
    <TABLE CELLPADDING=4  BORDER=1 WIDTH=100%>
        <tr style="border-bottom-style: solid">
        <td colspan="2"><b>E' stato trovato un solo file:</b></td>
        </tr>
        <tr style="border-bottom-style: solid">
        <td><b>Nome File</b></td>
        <td><b>Tipo</b></td>
        </tr>
        <TR>
            <TD ALIGN=LEFT><FONT FACE="Arial" SIZE=2><%="<a href='elencofile.asp?cartella="& Cartella & "' FP'>" & FP& "</a>"%></FONT></TD>
            <TD ALIGN=LEFT><FONT FACE="Arial" SIZE=2><%=DF%></FONT></TD>
        </TR>
    </TABLE>
    <%Else%>
    <TABLE CELLPADDING=4  BORDER=1 WIDTH=100%>
        <tr style="border-bottom-style: solid">
        <td colspan="2"><b>Sono stati trovati <%=Numero_File%> File:</b></td>
        </tr>
        <tr style="border-bottom-style: solid">
        <td><b>Nome File</b></td>
        <td><b>Tipo</b></td>
        </tr>
        <TR>
        <TD ALIGN=LEFT><FONT FACE="Arial" SIZE=2><%="<a href='" & Sotto_Cartella & "/" & Nome_File & "'>"& FP& "</a>"%></FONT></TD>
        <TD ALIGN=LEFT><FONT FACE="Arial" SIZE=2><%=DF%></FONT></TD>
        </TR>
    </TABLE>
    <%
    end if
    %>

  4. #4
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    Non ho visto tutto il listato, ma è solo il link finale che è sbagliato?
    Vedo che mostri a video FP ma il link contiene invece Nome_File

    Roby

  5. #5
    Utente di HTML.it
    Registrato dal
    May 2008
    Messaggi
    488
    Si, se mostro "FP" ma nel link metto "Nome_File" vedo a video tutti i file contenuti nella cartella e, se ci clicco su, si apre la finestra di download del file, che è ciò che voglio, tuttavia come dicevo il link è unico a prescindere dal fatto che cerco di cliccare su un'altro file in elenco.
    Infatti i file non vengono mostrati in righe differenti ma tutti nella stessa riga ???
    come devo fare per dividerli in modo da poter scegliere quale scaricare ?

  6. #6
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    I link li devi creare quando costruisci la riga e dovrai scriverla dinamicamente dentro il For Each
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  7. #7
    Utente di HTML.it
    Registrato dal
    May 2008
    Messaggi
    488
    Si infatti ci stavo provando solo che ho ancora qualche problema facendo così :

    codice:
    <% For Each File in fc %> 
        <TR>
        <TD ALIGN=LEFT><FONT FACE="Arial" SIZE=2><%="<a href='"& Sotto_Cartella & "/" & File.Name & "'>"& File.Name & "</a>"%></FONT></TD>
        <TD ALIGN=LEFT><FONT FACE="Arial" SIZE=2><%=DF%></FONT></TD>
        </TR>
        <%next%>

  8. #8
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    Il for/each è questo...
    For Each whatever in fc

    Roby

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.