Her er et script eksempel til søgning på harddisk, som du burde kunne bygge videre på.
Der bruges ActiveX, så det er kun MSIE der kan bruges som browser.
Scriptet skal lagres lokalt på din PC som .HTA = HTML Application for at du kan teste.
Hvis du lægger det på en webserver er der ikke adgang til drev, med mindre du har noget Intranet/Trusted Sites eller lignende sat op på klienterne.
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="
http://www.w3.org/1999/xhtml"><hta:application id="oHTA" applicationname="MyHTA">
<head>
<title>File Search</title>
<style type="text/css">
body {background-color: white; font-family : sans-serif;}
</style>
<script language="javascript">
var oFSO = new ActiveXObject("Scripting.FileSystemObject");
var CANCEL;
var searchWord;
var subDirArray = [];
var count;
var fcount;
var found;
var ResultTable;
function StartSearch() {
ResultTable=document.getElementById("resultTable");
while ( ResultTable.hasChildNodes() ) ResultTable.removeChild(ResultTable.lastChild);
CANCEL = false;
document.getElementById("startButton").disabled = true;
document.body.style.cursor = "wait";
searchWord = document.frmSearch.name.value;
subDirArray = [];
subDirArray[0] = document.frmSearch.folder.value;
count = 0;
fcount = 0;
found = 0;
SearchFolder();
}
function SearchFolder() {
if (count == subDirArray.length || CANCEL) {
document.getElementById("statusDiv").firstChild.nodeValue = ' ' + found + ' files found. ' + fcount + ' files searched in ' + count + ' directories.' + (CANCEL ? " Canceled!" : "");
document.getElementById("startButton").disabled = false;
document.body.style.cursor = "";
return;
}
document.getElementById("statusDiv").firstChild.nodeValue = subDirArray[count];
var objDir = oFSO.GetFolder(subDirArray[count]);
aFolders = new Enumerator(objDir.SubFolders);
for (var i=0;!aFolders.atEnd();aFolders.moveNext()) {
subDirArray[ subDirArray.length ] = aFolders.item().Path;
}
aFiles = new Enumerator(objDir.Files);
for (var i=0;!aFiles.atEnd();aFiles.moveNext()) {
SearchFile( aFiles.item() );
}
count++;
setTimeout( 'SearchFolder()', 1 );
}
function SearchFile( file ) {
fcount++;
if (file.Name.indexOf( searchWord ) > -1 ) {
found++;
var link = document.createElement("a");
var row = document.createElement("tr");
var cell1 = document.createElement("td");
var cell2 = document.createElement("td");
link.href = file.Path;
link.appendChild( document.createTextNode( file.Name + ' ') );
cell1.appendChild( link );
cell2.appendChild( document.createTextNode( ' ' + file.ParentFolder.Path) );
row.appendChild( cell1 );
row.appendChild( cell2);
document.getElementById( "resultTable" ).appendChild( row );
}
}
</script>
</head>
<body>
<form name="frmSearch">
Search:
<input type="text" name="name" value=".jar" size="10" title="Search text" >
<input type="text" name="folder" value="C:\Program Files\Java" size="99" title="Folder to search" >
<input type="button" id="startButton" value="Search Folder" onclick="StartSearch();">
<input type="button" value="Cancel" onclick="CANCEL=true;">
</form>
<div id="statusDiv">..</div>
<p>
<table border="0">
<thead><tr><th>File</th><th>Folder</th></tr></thead>
<tbody id="resultTable"></tbody>
</table>
</p>
</body>
</html>