Foros del Web » Programando para Internet » Javascript »

Buscador de archivos remoto

Estas en el tema de Buscador de archivos remoto en el foro de Javascript en Foros del Web. Muy buenas, estoy recien metiendome a fonod en este tema del javascript y me aparecio un problema, encontre el sgte codigo: Código: HTML><head><TITLE> Search... with ...
  #1 (permalink)  
Antiguo 28/10/2005, 09:30
 
Fecha de Ingreso: junio-2004
Mensajes: 15
Antigüedad: 19 años, 10 meses
Puntos: 0
Buscador de archivos remoto

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

Código:
HTML><head><TITLE>        Search... with sub-folders!
</TITLE></head>



<style>

.formItem {
    color: #000000;
    border: 1px solid #aaaaaa;
    background-color: #eeeeee;
}

.find {
    color: #0000ff;
    font: 10px Arial;
    }

.title {
    background-color: #dddddd;
    color: #000000;
    font: 12px arial;
    font-weight: bold;
    text-align: center;
    }

A {
    color: blue;
    text-decoration: none;
}

A:hover {
    text-decoration: underline;
}

</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 toMetric( bytes ) {

    // Check for Terabytes (TB).
    if( bytes >= 1099511627776 ) { return ( Math.floor( bytes / 1099511627776 ) + ' TB' ); }

    // Check for Gigabytes (GB).
    if( bytes >= 1073741824 ) { return ( Math.floor( bytes / 1073741824 ) + ' GB' ); }

    // Check for Megabytes (MB).
    if( bytes >= 1048576 ) { return ( Math.floor( bytes / 1048576 ) + ' MB' ); }

    // Check for Kilobytes (KB).
    if( bytes >= 1024 ) { return ( Math.floor( bytes / 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 subFolder( path ) {

    // Update the txtPath field with the new search folder.
    frmSearch.txtPath.value = unescape( path );

    // Restart a new search with the new folder.
    scan( );
}



// Scans the given path for files matching the given mask.
function FindFile( searchPath ) {

    // 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.GetParentFolderName( frmSearch.txtPath.value ).length > 0 ) {

            // Add the parent folder to the table result string.
            result +=
                '<tr' + ( ( toggle ) ? '' : ' BGCOLOR="#f0f0f0"' ) + '>' +
                '<td NOWRAP><FONT CLASS="find"> <A HREF="#" onclick="subFolder( \'' +
                escape( fso.GetParentFolderName( frmSearch.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 Enumerator( searchPath.SubFolders );

        // Iterate through the folders in the collection.
        for( var i = 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( \'' + escape( folder.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 Enumerator( searchPath.Files );

    // Iterate through the files in the collection.  Scan for files fitting the file mask.
    for( var i = 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.slice( 0, file.name.lastIndexOf( "." ) ).toLowerCase( ).indexOf( FileName ) > -1 ) {

            // Validate current file extention against search file extention parameter.
            if( Extention == "*" || file.name.slice( file.name.lastIndexOf( "." ) + 1 ).toLowerCase( ).indexOf( Extention ) > -1 ) {

                // 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"> ' +
                    toMetric( file.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( "." ) > -1 ) ? frmSearch.txtMask.value.slice( 0, frmSearch.txtMask.value.lastIndexOf( "." ) ) : ( frmSearch.txtMask.value.length > 0 ) ? frmSearch.txtMask.value.toLowerCase( ) : "*";
    Extention = ( frmSearch.txtMask.value.lastIndexOf( "." ) > -1 ) ? frmSearch.txtMask.value.slice( frmSearch.txtMask.value.lastIndexOf( "." ) + 1 ).toLowerCase( ) : "*";

    // Validate the given path.
    if( frmSearch.txtPath.value.length > 0 && fso.FolderExists( frmSearch.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.
        FindFile( fso.GetFolder( frmSearch.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....gracias
  #2 (permalink)  
Antiguo 28/10/2005, 19:42
Avatar de flaviovich  
Fecha de Ingreso: agosto-2005
Ubicación: Lima, Peru
Mensajes: 2.951
Antigüedad: 18 años, 8 meses
Puntos: 39
hola carlex!
Me parece que el problema esta en el uso del objeto FileSystemObject. Ya que este solo permite accesar en la maquina local. Puedo equivocarme, pero es solo una opinion.
En ese caso, habria que usar otro objeto en:
Código HTML:
var fso = new ActiveXObject( "Scripting.FileSystemObject" );
Espero haberte ayudado en algo.
suerte
__________________
No repitamos temas, usemos el Motor de busquedas
Plantea bien tu problema: Ayúdanos a ayudarte.
  #3 (permalink)  
Antiguo 28/10/2005, 20:07
 
Fecha de Ingreso: junio-2004
Mensajes: 15
Antigüedad: 19 años, 10 meses
Puntos: 0
Muchas gracias por tu respuesta e investigando un poco...si, tienes toda la razon , la variable efectivamente manda lo d la maquina local, ahora faltaria saber cual hace la misma tarea pero dentro del servidor, o lograr q el script corra en el servidor y no en la maquina local...espero q esto sea posible
  #4 (permalink)  
Antiguo 28/10/2005, 20:59
Avatar de flaviovich  
Fecha de Ingreso: agosto-2005
Ubicación: Lima, Peru
Mensajes: 2.951
Antigüedad: 18 años, 8 meses
Puntos: 39
Me parece que aca esta la solucion.
Solo que según lei aqui, no se podria, ya que necesitas tener derechos de administrador. Y esa vendria a ser la seguridad que ofrece WSH.
Seguro que en esta nueva version 5.6, ya no habran agujeros, porque antes existian, y por ahí se colo el famoso I LOVE YOU
Si logras algo, postealo!
__________________
No repitamos temas, usemos el Motor de busquedas
Plantea bien tu problema: Ayúdanos a ayudarte.
  #5 (permalink)  
Antiguo 07/11/2005, 14:32
 
Fecha de Ingreso: junio-2004
Mensajes: 15
Antigüedad: 19 años, 10 meses
Puntos: 0
Gracias por tus ideas flaviovich...pero creo q colgare lo cachos con este metodo y buscare otro...intente instalar el wsh para hacer correr el script pero no deja el windows 2003.....extranamente no paso las normas de seguridad (??)y no puede ser instalado...creo q vere alguna alternativa en php, gracias de todos modos por tu tiempo y colaboracion
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 03:35.