Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > HTML, Javascript y otros
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 28-10-2005
Carlex Carlex is offline
Miembro
 
Registrado: feb 2004
Ubicación: Bolivia
Posts: 88
Poder: 21
Carlex Va por buen camino
Unhappy Buscador de archivos remoto

Muy buenas, estoy recien metiendome a fondo en este tema del javascript y me aparecio un problema, encontre el sgte codigo:

Código PHP:
<HTML>
 <
head>
 <
TITLE>Search... with sub-folders!</TITLE>
 </
head>
 
 <
style type="text/css">
 
 .
formItem {
     
color#000000;
     
border1px solid #aaaaaa;
     
background-color#eeeeee;
 
}
 
 .
find {
     
color#0000ff;
     
font10px Arial;
     }
 
 .
title {
     
background-color#dddddd;
     
color#000000;
     
font12px arial;
     
font-weightbold;
     
text-aligncenter;
     }
 
 
{
     
colorblue;
     
text-decorationnone;
 }
 
 
A:hover {
     
text-decorationunderline;
 }
 
 </
STYLE>
 
 <
script LANGUAGE="JavaScript">
 
 
// Establish a few environment variables.
 
var fso = new ActiveXObject"Scripting.FileSystemObject" );
 var 
result = new String( );
 var 
FileName = new String( );
 var 
Extention = new String( );
 
 
 
// Converts file & folder byte size values to computer
 // metric (bytes, KB, MB, GB or TB). returns a string.
 
function toMetricbytes ) {
 
     
// Check for Terabytes (TB).
     
if( bytes >= 1099511627776 ) { return ( Math.floorbytes 1099511627776 ) + ' TB' ); }
 
     
// Check for Gigabytes (GB).
     
if( bytes >= 1073741824 ) { return ( Math.floorbytes 1073741824 ) + ' GB' ); }
 
     
// Check for Megabytes (MB).
     
if( bytes >= 1048576 ) { return ( Math.floorbytes 1048576 ) + ' MB' ); }
 
     
// Check for Kilobytes (KB).
     
if( bytes >= 1024 ) { return ( Math.floorbytes 1024 ) + ' KB' ); }
 
     
// The file is less than one KB, just return size as 1 KB like Windows does.
     
return '1 KB';
 }
 
 
 
// Show the contents of a clicked sub-folder.
 
function subFolderpath ) {
 
     
// Update the txtPath field with the new search folder.
     
frmSearch.txtPath.value unescapepath );
 
     
// Restart a new search with the new folder.
     
scan( );
 }
 
 
 
 
// Scans the given path for files matching the given mask.
 
function FindFilesearchPath ) {
 
     
// Extablish a table color toggle.
     
var toggle true;
 
     
// If chkShowFolders is checked, display the sub-folders.
     
if( frmSearch.chkShowFolders.checked ) {
 
         
// Check to see if the current folder is the drive root.
         
if( fso.GetParentFolderNamefrmSearch.txtPath.value ).length ) {
 
             
// Add the parent folder to the table result string.
             
result +=
                 
'<tr' + ( ( toggle ) ? '' ' BGCOLOR="#f0f0f0"' ) + '>' +
                 
'<td NOWRAP><FONT CLASS="find"> <A HREF="#" onclick="subFolder( \'' +
                 
escapefso.GetParentFolderNamefrmSearch.txtPath.value ) ) +
                 
'\' ); return false;">..</A> </FONT></td>' +
                 
'<td NOWRAP><FONT CLASS="find"> Parent folder </FONT></td>' +
                 
'<td NOWRAP ALIGN="right"><FONT CLASS="find"> </FONT></td></tr>';
 
             
// Toggle the color toggle variable.
             
toggle = !toggle;
         }
 
         
// Establish enumerator to step from folder to folder in the SubFolders collection.
         
var folderEnum = new EnumeratorsearchPath.SubFolders );
 
         
// Iterate through the folders in the collection.
         
for( var 0; !folderEnum.atEnd( ); folderEnum.moveNext( ) ) {
 
             
// Use a variable to hold the current file object to shorten the code below.
             
var folder folderEnum.item( );
 
             
// Add the folder to the table result string.
             
result +=
                 
'<tr' + ( ( toggle ) ? '' ' BGCOLOR="#f0f0f0"' ) + '>' +
                 
'<td NOWRAP><FONT CLASS="find"> <A HREF="#" ' +
                 
'onclick="subFolder( \'' escapefolder.Path ) + '\' ); return false;">' folder.name +
                 
'</A> </FONT></td>' +
                 
'<td NOWRAP><FONT CLASS="find"> ' folder.type ' </FONT></td>' +
                 
'<td NOWRAP ALIGN="right"><FONT CLASS="find"> </FONT></td></tr>';
 
             
// Toggle the color toggle variable.
             
toggle = !toggle;
         }
     }
 
     
// Establish enumerator to step from item to item in the folder contents.
     
var fileEnum = new EnumeratorsearchPath.Files );
 
     
// Iterate through the files in the collection. Scan for files fitting the file mask.
     
for( var 0; !fileEnum.atEnd( ); fileEnum.moveNext( ) ) {
 
         
// Use a variable to hold the current file object to shorten the code below.
         
var file fileEnum.item( );
 
         
// Validate current file against search filename parameter.
         
if( FileName == "*" || file.name.slice0,
           
file.name.lastIndexOf"." ) ).toLowerCase( ).indexOfFileName ) > -) {
 
             
// Validate current file extention against search file extention parameter.
             
if( Extention == "*" || file.name.slice(
               
file.name.lastIndexOf"." ) + ).toLowerCase( ).indexOfExtention ) > -) {
 
                 
// Add the file to the table result string.
                 
result +=
                     
'<tr' + ( ( toggle ) ? '' ' BGCOLOR="#f0f0f0"' ) + '>' +
                     
'<td NOWRAP><FONT CLASS="find"> <A TARGET="_blank" HREF="' +
                     
file.Path '">' file.name +
                     
'</A> </FONT></td>' +
                     
'<td NOWRAP><FONT CLASS="find"> ' file.type ' </FONT></td>' +
                     
'<td NOWRAP ALIGN="right"><FONT CLASS="find"> ' +
                     
toMetricfile.size ) + ' </FONT></td></tr>';
 
                 
// Toggle the color toggle variable.
                 
toggle = !toggle;
             }
         }
     }
 }
 
 
 
 
// Validates path and filename and initiates the file scan.
 
function scan( ) {
 
     
// Parse filename and extention from the given mask.
     
FileName = ( frmSearch.txtMask.value.lastIndexOf"." ) > -) ?
       
frmSearch.txtMask.value.slice0frmSearch.txtMask.value.lastIndexOf"." ) ) :
         ( 
frmSearch.txtMask.value.length ) ? frmSearch.txtMask.value.toLowerCase( ) : "*";
     
Extention = ( frmSearch.txtMask.value.lastIndexOf"." ) > -) ?
       
frmSearch.txtMask.value.slicefrmSearch.txtMask.value.lastIndexOf"." ) + ).toLowerCase( ) : "*";
 
     
// Validate the given path.
     
if( frmSearch.txtPath.value.length && fso.FolderExistsfrmSearch.txtPath.value ) ) {
 
         
// Path exists. Generate table headder.
         
result =
             
'<table BORDER="0" WIDTH="100%" CELLPADDING="0"><tr>' +
             
'<td WIDTH="60%" CLASS="title">Name</td>' +
             
'<td WIDTH="25%" CLASS="title">Type</td>' +
             
'<td WIDTH="15%" CLASS="title">Size</td></tr>';
 
         
// Collect valid filenames.
         
FindFilefso.GetFolderfrmSearch.txtPath.value ) );
 
         
// Close and display search results table.
         
outPut.innerHTML result "</table>";
 
     } else {
 
         
// Path is invalid. Alert user.
         
alert"Please enter a valid Path before proceeding." );
     }
 }
 
 
</script>
 
<body onload="frmSearch.txtMask.focus( ); frmSearch.txtMask.select( )"
   BGCOLOR="#ffffff" TOPMARGIN="0" LEFTMARGIN="0">
 
 <form ID="frmSearch" NAME="frmSearch">
 
 <table BORDER="0" CELLPADDING="0" STYLE="border-collapse: collapse;" CELLPADDING="2">
 <tr>
     <td><FONT FACE="Arial" SIZE="2"><B> Mask : </B></FONT></td>
     <td><input TYPE="text" VALUE="*.*" ID="txtMask" NAME="txtMask" CLASS="formItem" STYLE="width:600;"></td>
     </tr>
 <tr>
     <td><FONT FACE="Arial" SIZE="2"><B> Path : </B></FONT></td>
     <td><input TYPE="text" VALUE="C:\" ID="txtPath" NAME="txtPath" CLASS="formItem" STYLE="width:600;"></td>
     </tr>
 <tr>
     <td> </td>
     <td>
         <input TYPE="submit" VALUE="Search" CLASS="formItem" STYLE="width:150;"
             onclick="scan( ); frmSearch.txtMask.focus( ); frmSearch.txtMask.select( ); return false;">
 
         <input TYPE="checkbox" CHECKED ID="chkShowFolders" NAME="chkShowFolders"
             ><LABEL FOR="chkShowFolders">Show sub-folders</LABEL>
         </td>
     </tr>
 <tr>
     <td COLSPAN="2">
         <BR> <FONT FACE="arial" SIZE="2"><B> Search Result: </B></FONT>
         <HR>
         <DIV ID="outPut"></DIV>
         </td>
     </tr>
 </table>
 
 </form>
 
 </body>
 </HTML> 
Lo arregle a mi gusto para q busque solo en una determinada carpeta pero al ponerlo en linea no busca d manera remota solo local, alguien me puede dar una idea como modificar este codigo para q busque en el servidor y no asi en el cliente, esto lo hago para q sea mas facil subir archivos al server y no tener q meterlos a una base d datos....help

Última edición por dec fecha: 30-10-2005 a las 07:59:19. Razón: Un poco de por favor con el código que se adjunta... leñe...
Responder Con Cita
  #2  
Antiguo 28-10-2005
Avatar de jachguate
jachguate jachguate is offline
Miembro
 
Registrado: may 2003
Ubicación: Guatemala
Posts: 6.254
Poder: 28
jachguate Va por buen camino
Hola.

A menos que estes intentando implementar algo de AJAX (cosa que no creo), veo que tenes un problema de concepto aqui:

javascript se ejecuta en el cliente, por tanto, no tiene forma de saber lo que hay en el servidor. Bueno, si la tiene, pero será mucho mas complicado: podes conectarte via ftp a tu servidor y obtener la lista de carpetas, por ejemplo.

Si queres una lista de carpetas del servidor, será mejor que realices un script del lado del servidor (por ejemplo con php) o un cgi (por ejemplo con delphi) que te devuelva la lista de carpetas disponibles.

Hasta luego.

__________________
Juan Antonio Castillo Hernández (jachguate)
Guía de Estilo | Etiqueta CODE | Búsca antes de preguntar | blog de jachguate
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro


La franja horaria es GMT +2. Ahora son las 00:18:39.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi