quinta-feira, 15 de março de 2001

Liste os arquivos de um dir com nome, data, tamanho e etc

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0064)http://www.asp101.com/samples/download.asp?file=dir%5Flist%2Easp -->
<HTML>
<HEAD>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>
<META content="MSHTML 5.00.2614.3500" name=GENERATOR>
<title>[Ricardo - ASP]</title>
<style type="text/css">
<!--
a {  text-decoration: none}
-->
</style>
</HEAD>
<BODY bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<div align="center"><font face="Tahoma" size="2"><b><%
Function ShowImageForType(strName)
 Dim strTemp


 strTemp = strName
 
If strTemp <> "dir" Then
  strTemp = LCase(Right(strTemp, Len(strTemp) - InStrRev(strTemp, ".", -1, 1)))
 End If
 
Select Case strTemp
  Case "asp"
   strTemp = "asp"
  Case "dir"
   strTemp = "dir"
  Case "htm", "html"
   strTemp = "htm"
  Case "gif", "jpg"
   strTemp = "img"
  Case "txt"
   strTemp = "txt"
  Case Else
   strTemp = "misc"
 End Select
 strTemp = "<IMG SRC=""imagens/dir_" & strTemp & ".gif"" WIDTH=16 HEIGHT=16 BORDER=0>"


ShowImageForType = strTemp
End Function


%> <%
Dim strPath   'Path of directory to show
Dim objFSO    'FileSystemObject variable
Dim objFolder 'Folder variable
Dim objItem   'Variable used to loop through the contents of the folder


If Request.Form("Caminho") = "" Then
strPath = "/diretoriopadrao"
Else
strPath = Request.Form("Caminho")
End If


Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath(strPath))


%> Conte&uacute;do de <%= strPath %></b></font> <BR>
  <BR>
  <TABLE BORDER="1" CELLSPACING="0" CELLPADDING="2" BORDERCOLOR="#FF6633" width="750">
    <TR BGCOLOR="#FF6633">
      <TD align="center" valign="middle" height="45? width="72"><font color="#FFFFFF" face="Tahoma" size="2"><B>Nome:</B></font></TD>
      <TD align="center" valign="middle" height="45" width="115"><font color="#FFFFFF" face="Tahoma" size="2"><B>Tamanho
        (kb):</B></font></TD>
      <TD align="center" valign="middle" height="45" width="185"><font color="#FFFFFF" face="Tahoma" size="2"><B>Data
        Cria&ccedil;&atilde;o:</B></font></TD>
      <TD align="center" valign="middle" height="45" width="126"><font face="Tahoma" size="2" color="#FFFFFF"><b>Ultima
        Modifica&ccedil;&atilde;o:</b></font></TD>
      <TD valign="middle" align="center" height="45" width="220"><font color="#FFFFFF" face="Tahoma" size="2"><B>Tipo:</B></font></TD>
    </TR>
    <%
For Each objItem In objFolder.SubFolders
 If InStr(1, objItem, "_vti", 1) = 0 Then
 %>
   
<TR BGCOLOR="#FFFFFF">
      <TD ALIGN="left" width="72" ><font face="Tahoma" size="2" color="#000000"><%= ShowImageForType("dir") %>&nbsp;<A HREF="<%= strPath & "/" & objItem.Name %>"><%= objItem.Name %></A></font></TD>
      <TD ALIGN="right" width="115"><font face="Tahoma"  size="2" color="#000000"><%= objItem.Size/1024 %></font></TD>
      <TD ALIGN="left" width="185" ><font face="Tahoma"  size="2" color="#000000"><%= objItem.DateCreated %></font></TD>
      <TD ALIGN="left" width="126" >
        <div align="center"><font face="Tahoma" size="2" color="#000000"><%= objItem.DateLastModified
 %>
</font></div>
      </TD>
      <TD ALIGN="left" width="220" ><font face="Tahoma" size="2" color="#000000"><%= objItem.Type %></font></TD>
    </TR>
    <%
End If
Next
For Each objItem In objFolder.Files
%>
   
<TR BGCOLOR="#FFFFFF">
      <TD font color="#FFFFFF" face="Tahoma" size="2" width="72"><font face="Tahoma" size="2" color="#000000"><%= ShowImageForType(objItem.Name) %>&nbsp;<A HREF="<%= strPath & "/" & objItem.Name %>"><%= objItem.Name %></A></font></TD>
      <TD font color="#FFFFFF" face="Tahoma" size="2"  ALIGN="right" width="115"><font face="Tahoma"  size="2" color="#000000"><%= objItem.Size/1024 %></font></TD>
      <TD color="#FFFFFF" face="Tahoma" size="2" ALIGN="left" width="185" ><font face="Tahoma" size="2" color="#000000"><%= objItem.DateCreated %></font></TD>
      <TD color="#FFFFFF" face="Tahoma" size="2" ALIGN="left" width="126" >
        <div align="center"><font face="Tahoma" size="2" color="#000000"><%= objItem.DateLastModified
 %>
</font></div>
      </TD>
      <TD color="#FFFFFF" face="Tahoma" size="2" ALIGN="left" width="220" ><font face="Tahoma" size="2" color="#000000"><%= objItem.Type %></font></TD>
    </TR>
    <%
Next
%>
 
</TABLE>
  <br>
  <form method="post" action="dir_list.asp" name="form">
    <input type="text" name="caminho">
    <input type="submit" name="Submit" value="Ir">
    <br>
    <br>
    <br>
    </form>
</div>
</BODY></HTML>



Esta matéria foi postada originalmente no ASP4Developers por Ricardo Costa (site), que na época era "Programador Delphi, Java, ASP e PHP de uma produtora de Web Sites (www.icorp.com.br) e estou cursando graduação em Ciências da Computação na UNICAP". Hoje, vai saber...

0 comentários: