Foros del Web » Programando para Internet » ASP Clásico »

Navegar por los directorios del server.

Estas en el tema de Navegar por los directorios del server. en el foro de ASP Clásico en Foros del Web. Muy wenas a tod@s, tengo el siguiente problemilla. Encontré un código para mostrar al usuario los ficheros que hay en una carpeta del servidor. Este ...
  #1 (permalink)  
Antiguo 09/06/2004, 04:11
Avatar de angel_dope  
Fecha de Ingreso: noviembre-2002
Ubicación: Valencia
Mensajes: 737
Antigüedad: 21 años, 6 meses
Puntos: 8
Pregunta Navegar por los directorios del server.

Muy wenas a tod@s, tengo el siguiente problemilla. Encontré un código para mostrar al usuario los ficheros que hay en una carpeta del servidor. Este código crea un recordset y los muestra por pantalla, lo único que yo le añadí fue un enlace a cada arxivo que se muestra. Pero ahora lo que necesito es que además de los archivos, muestre tb las subcarpetas que estén dentro de esa carpeta, y que se puedan mover por ellas. Lo que habia pensado era, a la vez que se muestran los archivos, que se muestren las carpetas, y al pinchar en una carpeta, que llame a la misma página .asp pasandole como parametro el nombre de la carpeta que he hemos seleccionado, para asi crear una nueva ruta en el recordset y que me vuelva a sacar los arxivos (y subcarpetas si las hubiese) que hay en esa carpeta en la que hemos pinchado. Creo que se puede hacer, verdad?? El problema está en que no se como mostrar las subcarpetas Espero que alguien pueda ayudarme con esto.
Os dejo aqui el código que estoy usando para ver si alguien me puede ayudar a modificarlo:

Código PHP:
<%@LANGUAGE="VBSCRIPT"%> 
<!--
#include file="Connections/intranet.asp" -->
<%
%>
<
html>
<
head>
<
title>Untitled Document</title>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</
head>
<
body background="logo.png" text="#5E82AB" link="#5E82AB" vlink="#5E82AB" alink="#5E82AB">
<%
usuario Request.ServerVariables("logon_user")
array1 split(usuario,"\",2)
usuario2 = array1(1)


'kc_fsoFiles
'Purpose:
'    1.    To create a recordset using the FSO object and ADODB
'    2.    Allows you to exclude files from the recordset if needed
'Use:
'    1.    Call the function when you're ready to open the recordset
'        and output it onto the page.
'    example:
'        Dim rsFSO, strPath
'        strPath = Server.MapPath("
PlayGroundFSOStuff")
'        Set rsFSO = kc_fsoFiles(strPath, "
_")
'        The "
_" will exclude all files beginning with 
'        an underscore 
Function kc_fsoFiles(theFolder, Exclude)
Dim rsFSO, objFSO, objFolder, File
Const adInteger = 3
Const adDate = 7
Const adVarChar = 200
    'create an ADODB.Recordset and call it rsFSO
    Set rsFSO = Server.CreateObject("
ADODB.Recordset")
    'Open the FSO object
    Set objFSO = Server.CreateObject("
Scripting.FileSystemObject")
        'go get the folder to output it's contents
        Set objFolder = objFSO.GetFolder(theFolder)
    'Now get rid of the objFSO since we're done with it.
    Set objFSO = Nothing
        'create the various rows of the recordset
        rsFSO.Fields.Append "
Name", adVarChar, 200
        rsFSO.Fields.Append "
Type", adVarChar, 200
        rsFSO.Fields.Append "
DateCreated", adDate
        rsFSO.Fields.Append "
DateLastAccessed", adDate
        rsFSO.Fields.Append "
DateLastModified", adDate
        rsFSO.Fields.Append "
Size", adInteger
        rsFSO.Fields.Append "
TotalFileCount", adInteger
        rsFSO.Open
        
        'Now let's find all the files in the folder
        For Each File In objFolder.Files
            'hide any file that begins with the character to exclude
            If (Left(File.Name, 3)) <> Exclude Then 
                rsFSO.AddNew
                rsFSO("
Name") = File.Name
                rsFSO("
Type") = File.Type
                rsFSO("
DateCreated") = File.DateCreated
                rsFSO("
DateLastAccessed") = File.DateLastAccessed
                rsFSO("
DateLastModified") = File.DateLastModified
                rsFSO("
Size") = File.Size
                rsFSO.Update
            End If
        Next
        'And finally, let's declare how we want the files 
        'sorted on the page. In this example, we are sorting 
        'by File Type in  descending order,
        'then by Name in an ascending order.
        rsFSO.Sort = "
Type DESCSize ASC "

    'Now get out of the objFolder since we're done with it.
    Set objFolder = Nothing

    'now make sure we are at the beginning of the recordset
    'not necessarily needed, but let's do it just to be sure.
    rsFSO.MoveFirst()
    Set kc_fsoFiles = rsFSO
End Function

'Now let's call the function and open the recordset on the page

'the folder we will be displaying
Dim strFolder : strFolder = Server.MapPath("
....datosred") 
'Aqui arriba faltan las barras invertidas, no me las saca, aunq no se xq, 
'sería "
Server.MapPath("..\..\datosred\")"

'the actual recordset we will be creating with the kc_fsoFiles function
Dim rsFSO '
now let's call the function and open the recordset
'
we will exclude all files beginning with a "_"
Set rsFSO kc_fsoFiles(strFolder"-")

'now we'll create a loop and start displaying the folder
'contents with our recordset. Of course, this is just a
'
simple example and not very well formattedi.e., not in
'a table, but it gets the point across on how you can
'
ouput the recordset on the page.
%>
<
p><font face="Arial, Helvetica, sans-serif"><b>Documentos disponibles:</b></font></p>
<
table width="65%" border="1" align="center">
  <
tr
    <
td width="68%"
      <
div align="center"><font face="Arial, Helvetica, sans-serif"><b>Nombre</b></font></div>
    </
td>
    <
td width="32%"
      <
div align="center"><font face="Arial, Helvetica, sans-serif"><b>Tipo de 
        Archivo
</b></font></div>
    </
td>
  </
tr>
  <%
While 
Not rsFSO.EOF
enlace 
"../../datosred/" rsFSO("Name").Value
%>
  <
tr
    <
td width="68%"
      <
div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><a href="<%=enlace%>"><%= rsFSO("Name").Value %> </a></font></div>
    </
td>
    <
td width="32%"
      <
div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><%= rsFSO("Type").Value %></font></div>
    </
td>
  </
tr>
  <%
    
'and let's move to the next record
    rsFSO
.MoveNext()
Wend
%>
</
table>
<%
finallyclose out the recordset
rsFSO
.close()
Set rsFSO Nothing

%>
</
body>
</
html
Muchas gracias por adelantado a todo el mundo, salu2
__________________
Vayamos por Partes :: Jack el Destripador
  #2 (permalink)  
Antiguo 09/06/2004, 08:03
Avatar de tuning_boy  
Fecha de Ingreso: mayo-2004
Ubicación: Madrid
Mensajes: 45
Antigüedad: 20 años
Puntos: 0
No te vale con poner desde la configuracion del IIS el directorio como navegable, te haria lo que quieres el solo
__________________
Si te gusta el tuning ...
http://www.comunidad-tuning.com
  #3 (permalink)  
Antiguo 09/06/2004, 08:04
Avatar de angel_dope  
Fecha de Ingreso: noviembre-2002
Ubicación: Valencia
Mensajes: 737
Antigüedad: 21 años, 6 meses
Puntos: 8
No, eso lo habia pensado, pero la cosa está en que necesito saber en que directorio estoy, xq tb hay una opción de subir archivos. Si pongo el directorio como navegable, puedo moverme x ahi y ver los archivos, pero no pillar la ruta para subir algo ahi, o hay alguna manera???
__________________
Vayamos por Partes :: Jack el Destripador
  #4 (permalink)  
Antiguo 10/06/2004, 00:36
Avatar de angel_dope  
Fecha de Ingreso: noviembre-2002
Ubicación: Valencia
Mensajes: 737
Antigüedad: 21 años, 6 meses
Puntos: 8
A nadie se le ocurre nada???
__________________
Vayamos por Partes :: Jack el Destripador
  #5 (permalink)  
Antiguo 10/06/2004, 04:37
Avatar de angel_dope  
Fecha de Ingreso: noviembre-2002
Ubicación: Valencia
Mensajes: 737
Antigüedad: 21 años, 6 meses
Puntos: 8
Ya lo he solucionado, menos mal!!! Aqui os dejo el código por si alguien lo necesita ;)

Código PHP:
<%@LANGUAGE="VBSCRIPT"%> 
<!--
#include file="Connections/intranet.asp" -->
<%
usuario Request.ServerVariables("logon_user")
array1 split(usuario,"\",2)
usuario2 = array1(1)

Ruta = Request.QueryString("
Path")

If Ruta = "" then
Ruta= "
../../datosred/"
Else
Ruta = "
../../datosred/" & Ruta & "/"
End if

Set FSO = CreateObject("
Scripting.FileSystemObject")
Set Carpeta = FSO.GetFolder(Server.MapPath(ruta))
Set Subcarpetas = Carpeta.SubFolders
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="
Content-Type" content="text/htmlcharset=iso-8859-1">
</head>
<body background="
logo.png" text="#5E82AB" link="#5E82AB" vlink="#5E82AB" alink="#5E82AB">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <
tr
    <
td><font face="Arial, Helvetica, sans-serif"><b>Carpetas:</b></font></td>
    <
td
      <
div align="right"><a href="javascript:window.history.back(1)"><img src="back.gif" width="50" height="43" border="0"></a></div>
    </
td>
  </
tr>
</
table>
<%For 
Each SubCarpeta in Subcarpetas
            SubCNombre 
Subcarpeta.Name    
        
If Request.Querystring("path") = "" THEN %>
- <
a href="documentos.asp?Path=<%=Request.QueryString("Path") & SubCNombre %>"
<% = 
SubCNombre %>
</
A><br>
<% else %>
- <
a href="documentos.asp?Path=<%=Request.QueryString("Path") & "/" & SubCNombre %>"
<% = 
SubCNombre %>
</
A><br>
<%    
END IF 
        
Next %>
<%
'kc_fsoFiles
'
Purpose:
'    1.    To create a recordset using the FSO object and ADODB
'    
2.    Allows you to exclude files from the recordset if needed
'Use:
'    
1.    Call the function when you're ready to open the recordset
'        
and output it onto the page.
'    example:
'        
Dim rsFSOstrPath
'        strPath = Server.MapPath("\PlayGround\FSO\Stuff\")
'        
Set rsFSO kc_fsoFiles(strPath"_")
'        The "_" will exclude all files beginning with 
'        
an underscore 
Function kc_fsoFiles(theFolderExclude)
Dim rsFSOobjFSOobjFolderFile
Const adInteger 3
Const adDate 7
Const adVarChar 200
    
'create an ADODB.Recordset and call it rsFSO
    Set rsFSO = Server.CreateObject("ADODB.Recordset")
    '
Open the FSO object
    Set objFSO 
Server.CreateObject("Scripting.FileSystemObject")
        
'go get the folder to output it's contents
        Set objFolder 
objFSO.GetFolder(theFolder)
    
'Now get rid of the objFSO since we're done with it.
    
Set objFSO Nothing
        
'create the various rows of the recordset
        rsFSO.Fields.Append "Name", adVarChar, 200
        rsFSO.Fields.Append "Type", adVarChar, 200
        rsFSO.Fields.Append "DateCreated", adDate
        rsFSO.Fields.Append "DateLastAccessed", adDate
        rsFSO.Fields.Append "DateLastModified", adDate
        rsFSO.Fields.Append "Size", adInteger
        rsFSO.Fields.Append "TotalFileCount", adInteger
        rsFSO.Open
        
        '
Now let's find all the files in the folder
        For Each File In objFolder.Files
            '
hide any file that begins with the character to exclude
            
If (Left(File.Name3)) <> Exclude Then 
                rsFSO
.AddNew
                rsFSO
("Name") = File.Name
                rsFSO
("Type") = File.Type
                rsFSO
("DateCreated") = File.DateCreated
                rsFSO
("DateLastAccessed") = File.DateLastAccessed
                rsFSO
("DateLastModified") = File.DateLastModified
                rsFSO
("Size") = File.Size
                rsFSO
.Update
            End 
If
        
Next
        
'And finally, let'declare how we want the files 
        
'sorted on the page. In this example, we are sorting 
        '
by File Type in  descending order,
        
'then by Name in an ascending order.
        rsFSO.Sort = "Name Asc, Size ASC "

    '
Now get out of the objFolder since we're done with it.
    Set objFolder = Nothing

    '
now make sure we are at the beginning of the recordset
    
'not necessarily needed, but let'do it just to be sure.
    
rsFSO.MoveFirst()
    
Set kc_fsoFiles rsFSO
End 
Function

'Now let's call the function and open the recordset on the page

'the folder we will be displaying
Dim strFolder : strFolder = Server.MapPath("..\..\datosred\" & Request.QueryString("Path"))


'
the actual recordset we will be creating with the kc_fsoFiles function
Dim rsFSO 'now let's call the function and open the recordset
'we will exclude all files beginning with a "_"
Set rsFSO = kc_fsoFiles(strFolder, "-")

'
now we'll create a loop and start displaying the folder
'
contents with our recordsetOf coursethis is just a
'simple example and not very well formatted, i.e., not in
'
a tablebut it gets the point across on how you can
'ouput the recordset on the page.
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><font face="Arial, Helvetica, sans-serif"><b>Documentos disponibles en 
      la carpeta: <%=Request.Querystring("Path")%></b></font></td>
    <td>
      <div align="right"><font face="Arial, Helvetica, sans-serif"><b><a href="javascript:window.history.back(1)"><img src="back.gif" width="50" height="43" border="0"></a></b></font></div>
    </td>
  </tr>
</table>
<table width="65%" border="1" align="left" cellpadding="0" cellspacing="0">
  <tr> 
    <td width="42%"> 
      <div align="center"><font face="Arial, Helvetica, sans-serif"><b>Nombre</b></font></div>
    </td>
    <td width="28%"> 
      <div align="center"><font face="Arial, Helvetica, sans-serif"><b>Tipo de 
        Archivo</b></font></div>
    </td>
    <td width="18%"> 
      <div align="center"><font face="Arial, Helvetica, sans-serif"><b> &Uacute;ltima 
        Modificaci&oacute;n </b></font></div>
    </td>
    <td width="12%"> 
      <div align="center"><font face="Arial, Helvetica, sans-serif"><b>Tama&ntilde;o</b></font></div>
    </td>
  </tr>
  <%
While Not rsFSO.EOF
enlace = "../../datosred/"& Request.QueryString("Path") &"/"& rsFSO("Name").Value
%>
  <tr> 
    <td width="42%"> 
      <div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><a href="<%=enlace%>"><%= rsFSO("Name").Value %> </a></font></div>
    </td>
    <td width="28%"> 
      <div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><%= rsFSO("Type").Value %></font></div>
    </td>
    <td width="18%"> 
      <div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><%= rsFSO("DateLastModified").Value %></font></div>
    </td>
    <td width="12%"> 
      <div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><%= rsFSO("Size").Value/1000 &" Kb" %></font></div>
    </td>
  </tr>
  <%
    '
and let's move to the next record
    rsFSO.MoveNext()
Wend
%>
</table>
<p> 
  <%
'
finallyclose out the recordset
rsFSO
.close()
Set rsFSO Nothing

%>
</
p>
</
body>
</
html
__________________
Vayamos por Partes :: Jack el Destripador
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:27.