 |
|
 |
Hi, I am a newbie in Jscript, and i would like to know if there is a way to link the results to the files? Help me getting to this... Thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Below is the advanced search code in its entirety... you will also need the Progressbar.gif to be in the same directory as the advancedsearch.htm
<HTML><HEAD><TITLE> Drive Search</TITLE></HEAD>
<STYLE> img { padding: 0px; margin: 0px; border: none; }
.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>
// Establish a few environment variables. var fso = new ActiveXObject( "Scripting.FileSystemObject" ); var result = new String( ); var FileName = new String( ); var Extention = new String( ); var filepath = new Array(); var subfoldarray = new Array(); var x = 0; var c = 0;
// 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;
// Establish enumerator to step from folder to folder in the SubFolders collection. var folderEnum = new Enumerator( searchPath.SubFolders );
k=0; 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( ); // send folder path into array for use later subfoldarray[k]=folder.path; //call subfolder function to search through for files subFolder(subfoldarray[k]); k++; }
// 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. x=0; 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. var mydate = new Date() //set mydate for use in output and sort mydate.setYear(mydate.getYear()- frmSearch.form_date.value) if (file.DateLastModified <= mydate){ filepath[x] = new filefunction(file.Path, file.name, file.type, file.DateLastModified, file.size); //alert(filepath[x].Path); x++; } } } } // calls the sort function on the array filepath.sort(sortDateModified); for(i=0; i<x; i++){ //outputs sorted results c++ //outputs files to table result += '<TR' + ( ( toggle ) ? '' : ' BGCOLOR="#f0f0f0"' ) + '>' + '<TD NOWRAP><FONT CLASS="find"> <A TARGET="_blank" HREF="' + filepath[i].Path + '">' + filepath[i].name + '</A> </FONT></TD>'+ '<TD NOWRAP><FONT CLASS="find"> '+ searchPath +' </FONT></TD>' + '<TD NOWRAP><FONT CLASS="find"> ' + filepath[i].type + ' </FONT></TD>' + '<TD NOWRAP><FONT CLASS="find"> '+ filepath[i].DateLastModified +' </FONT></TD>' + '<TD NOWRAP ALIGN="right"><FONT CLASS="find"> ' + toMetric( filepath[i].size ) + ' </FONT></TD><TD><input style="visibility:visible;" id ="delete" type="Button" name="del" class="formItem" value="Delete" onClick="deleteFile(this, "'+ escape(searchPath) + '/'+ filepath[i].name + '" , "'+ filepath[i].name + '" ;"></TD></TR>'; // Toggle the color toggle variable. toggle = !toggle; // sends the cout out to Search Results: frmSearch.resultcnt.value = c + " Files"; } } // filefunction holds values of multidem array for sorting and other functions function filefunction(path, Name, Type, datemodified, Size){ this.Path = path; this.name = Name; this.type = Type; this.DateLastModified = datemodified; this.size = Size; }
// delete file function function deleteFile (fldname, fpath, fname){ //alert (escape(fpath)); var answer = confirm('Are you sure you want to delete '+fname+'?'); if(answer){ var deleteobject; deleteobject = new ActiveXObject("Scripting.FileSystemObject"); deleteobject.DeleteFile(unescape(fpath)); //calls header output function to and rescans after the file is deleted disabledelete(fldname) }else{} }
function disabledelete(flaname){ flaname.style.visibility = 'hidden'; }
// sort date function function sortDateModified(a, b) { var x = b.DateLastModified; var y = a.DateLastModified; return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }
function progressbar(){ var width = 320; var height = 200; var left = (screen.width - width)/2; var top = (screen.height - height)/2; newwindow2=window.open('','Progress','height=200,width=320,top='+top+',left='+left+''); var tmp = newwindow2.document; tmp.write('<html><head><title>Progress</title>'); tmp.write('</head><body><p>Please Wait<br><br><img src="progressbar.gif"/></p>'); tmp.write('</body></html>'); tmp.close(); }
// sends header output to page and scans directory function headerOutput(){ //resets path to main directory frmSearch.txtPath.value = frmSearch.txtPath.value; //sets the header info frmSearch.resultcnt.value = 0 + " Files"; result = '<TABLE BORDER="0" WIDTH="100%" CELLPADDING="5"><TR>' + '<TD WIDTH="60%" CLASS="title">File Name</TD>' + '<TD WIDTH="20%" CLASS="title">Path</TD>'+ '<TD WIDTH="25%" CLASS="title">Type</TD>' + '<TD WIDTH="15%" CLASS="title">Last Modified</TD>' + '<TD WIDTH="15%" CLASS="title">Size</TD>' + '<TD WIDTH="15%" CLASS="title">Delete File</TD></TR>'; //resets total count for new search c=0; //reset arrays for new search FileName = new String( ); Extention = new String( ); filepath = new Array(); subfoldarray = new Array(); //scans the current directory progressbar(); scan(); newwindow2.close();
}
// 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 ) ) {
// 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"> <center> <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="Y:\" ID="txtPath" NAME="txtPath" CLASS="formItem" STYLE="width:600; visibility:visible;"><INPUT TYPE="text" VALUE="Y:\" ID="txtOrigPath" NAME="txtOrigPath" CLASS="formItem" STYLE="width ; visibility:hidden;"></TD> </TR> <TR> <TD> </TD> <TD><font size="-1" color="#666666"><i> *Following the search the path will reflect the last folder found in the specified directory. <u><br>example</u>: search "c:\windows" results "c:\windows\system\"</i></font></TD> </TR> <TR> <TD> </TD> </TR> <TR> <TD> </TD> <TD> <INPUT TYPE="button" VALUE="Search" CLASS="formItem" STYLE="width:150;" onClick="headerOutput( ); frmSearch.txtMask.focus( ); frmSearch.txtMask.select( );return false;"> Older Than:<select name="form_date"> <option value="20">20yrs</option><option value="19">19yrs</option><option value="18">18yrs</option> <option value="17">17yrs</option><option value="16">16yrs</option><option value="15">15yrs</option><option value="14">14yrs</option> <option value="13">13yrs</option><option value="12">12yrs</option><option value="11">11yrs</option><option value="10">10yrs</option> <option value="9">9yrs</option><option value="8">8yrs</option><option value="7">7yrs</option><option value="6">6yrs</option><option value="5">5yrs</option><option value="4">4yrs</option><option value="3">3yrs</option></select> <font size="-1" color="#666666"><i> < Please select the age of the files</i></font></TD> </TD> </TR> <TR> <TD COLSPAN="2"> <BR> <FONT FACE="arial" SIZE="2"><B> Search Result: </B></FONT><input readonly style="text-align:center; border:none; color:red;" name="resultcnt" size="6" value=""> <font size="-1" color="#666666"><i> <u><b>Tip</b></u>: To cycle through files and delete quicker use Tab2x, Enter2x combination</i></font> <HR> <div id="preload" style="visibility:hidden;"><img height="20" width="500" src="progressbar.gif"/></div> <DIV ID="outPut"></DIV> </TD> </TR> </TABLE>
</FORM>
</center> </BODY></HTML>
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
below is a copy of the source code and progress bar gif.... after trying to copy and paste the code from the page i realized it breaks the javascript due to line break issues. So the simple fix is to put the entire page up for download. Hope this helps  advancedsearch.zip
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
This script is awesome, I've been tooling around with it and would like to get the results to be populated to an excel spreadsheet.
I've no working code yet but just wondering if someone may already have something that works for this?
- Popsui
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I never had this requested but you are right. The option to do such a thing would be very cool. I do know that the output is already being delivered to the screen via tables so getting this into a spreadsheet shouldn't be too hard. I'll work on it in my spare time :P I've already got the source code modified to where it looks through all folders and no longer displays the .. as a base or any of the folders in the results. I removed the check box to display subfolders because it is no longer needed. The way it works now is you give it a drive or base folder. Example: C:\ it looks through every folder under that root and gives the files located within each folder similar to windows search application. The option to delete any of the files will be to the right and you can still click the file name and view the file. Now the folder path will be displayed in a column to the right of the file (example: if i searched the c:\ then a file might have c:\windows as a path). It will also alert the user and ask are you sure before deleting. I'll have the code posted soon
modified on Wednesday, December 31, 2008 3:34 PM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
What if we want to have an alert if there is no file found? Or have something that lets the user know that the search is in progress? I've been trying to do something like this but just can't get it to work. Any help would be greatly appreciated.
modified on Tuesday, May 27, 2008 11:55 AM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I know I answered my own request with this one but i needed it and I worked on it till I figured it out. So here ya go hope it benifits someone else who needed it.
<HTML><HEAD><TITLE> </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( ); var filepath = new Array(); var x = 0;
// 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. x=0; 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. var mydate = new Date() mydate.setYear(mydate.getYear()- frmSearch.form_date.value) if (file.DateLastModified <= mydate){ filepath[x] = new filefunction(file.Path, file.name, file.type, file.DateLastModified, file.size); //alert(filepath[x].Path); x++; }
} } } // calls the sort function on the array filepath.sort(sortDateModified); for(i=0; i<x;i++){ //outputs sorted results result += '<TR' + ( ( toggle ) ? '' : ' BGCOLOR="#f0f0f0"' ) + '>' + '<TD NOWRAP><FONT CLASS="find"> <A TARGET="_blank" HREF="' + filepath[i].Path + '">' + filepath[i].name + '</A> </FONT></TD>' + '<TD NOWRAP><FONT CLASS="find"> ' + filepath[i].type + ' </FONT></TD>' + '<TD NOWRAP><FONT CLASS="find"> '+ filepath[i].DateLastModified +' </FONT></TD>' + '<TD NOWRAP ALIGN="right"><FONT CLASS="find"> ' + toMetric( filepath[i].size ) + ' </FONT></TD><TD><input type="Button" name=delete" class="formItem" value="Delete" onClick="deleteFile("'+ filepath[i].Path + '" "></TD></TR>'; // Toggle the color toggle variable. toggle = !toggle; } } // filefunction holds values of multidem array for sorting and other functions function filefunction(path, Name, Type, datemodified, Size){ this.Path = path; this.name = Name; this.type = Type; this.DateLastModified = datemodified; this.size = Size; }
// delete file function function deleteFile(fpath){ var answer = confirm('Are you sure you want to delete '+fpath+'?'); if(answer){ var deleteobject; deleteobject = new ActiveXObject("Scripting.FileSystemObject"); deleteobject.DeleteFile(fpath); scan(); }else{} }
// sort date function function sortDateModified(a, b) { var x = b.DateLastModified; var y = a.DateLastModified; return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }
// 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="5"><TR>' + '<TD WIDTH="60%" CLASS="title">Name</TD>' + '<TD WIDTH="25%" CLASS="title">Type</TD>' + '<TD WIDTH="15%" CLASS="title">Last Modified</TD>' + '<TD WIDTH="15%" CLASS="title">Size</TD>' + '<TD WIDTH="15%" CLASS="title">Delete File</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">
<center> <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="Y:\" 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> Older Than:<select name="form_date"> <option value="6">6yrs</option><option value="5">5yrs</option><option value="4">4yrs</option><option value="3">3yrs</option></select> </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>
</center> </BODY></HTML>
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Sorry about the frustration if i caused any with this code... the delete function seems to be buggy. i will have an update to this script posted soon that will make it more user friendly and easier to search directories. Thanks, Jason
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Thanks again for starting this thread.. this program has been a great value... recently I made some changes due to a request...
If anyone could modify this to include a delete button for each of the listed files please contact me Djjman@bellsouth.net
<HTML><HEAD><TITLE> </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( ); var filepath = new Array(); var x = 0;
// 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. x=0; 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. var mydate = new Date() mydate.setYear(mydate.getYear()- frmSearch.form_date.value) if (file.DateLastModified <= mydate){ filepath[x] = new filefunction(file.Path, file.name, file.type, file.DateLastModified, file.size); //alert(filepath[x].Path); x++; }
} } } filepath.sort(sortDateModified); for(i=0; i<x;i++){ result += '<TR' + ( ( toggle ) ? '' : ' BGCOLOR="#f0f0f0"' ) + '>' + '<TD NOWRAP><FONT CLASS="find"> <A TARGET="_blank" HREF="' + filepath[i].Path + '">' + filepath[i].name + '</A> </FONT></TD>' + '<TD NOWRAP><FONT CLASS="find"> ' + filepath[i].type + ' </FONT></TD>' + '<TD NOWRAP><FONT CLASS="find"> '+ filepath[i].DateLastModified +' </FONT></TD>' + '<TD NOWRAP ALIGN="right"><FONT CLASS="find"> ' + toMetric( filepath[i].size ) + ' </FONT></TD></TR>'; // Toggle the color toggle variable. toggle = !toggle; } }
function filefunction(path, Name, Type, datemodified, Size){ this.Path = path; this.name = Name; this.type = Type; this.DateLastModified = datemodified; this.size = Size; }
function sortDateModified(a, b) { var x = b.DateLastModified; var y = a.DateLastModified; return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }
// 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">Last Modified</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">
<center> <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="Y:\" 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> Older Than:<select name="form_date"> <option value="6">6yrs</option><option value="5">5yrs</option><option value="4">4yrs</option><option value="3">3yrs</option></select> </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>
</center> </BODY></HTML>
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
I execute the sample in a c:\zip directory with 7 files either from the desktop or the directory itself and does not work for me in windows vista. Any Help? Regards
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Hi, When the path is say, C:\temp i get error for this line - for(i=0;!FSo.atEnd();FSo.moveNext())
and if I do C:\temp\, then it fails here itself - var FSo = new Enumerator(FOo.Files);
Why does this happen?
Thanks.
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
 |
Hi ,
How can i search the files in the folders without using 'ActiveXObject("Scripting.FileSystemObject")' ie using the plain javascript.
Please anyone help me out..its very urgent
Keertikiran
|
| Sign In·View Thread·PermaLink | 1.75/5 (7 votes) |
|
|
|
 |
|
|
 |
|
 |
Hi,
I want to display the search result in alphabetical order after search.. ie., if i want to search the files starting from 'A', the results should be 'a1.txt', a2.txt','ab1.doc'...
Can anyone help me out pls..
-- modified at 5:16 Wednesday 4th April, 2007
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
If you look at the code for the date modified which is posted at the top of the thread... there is a sort function in there... all you need to do is change the criteria and and use the column or link to call the new function...
so
//create your array to hold the values filepath[x] = new filefunction(file.Path, file.name, file.type, file.DateLastModified, file.size); //alert(filepath[x].Path); x++; //create the function to hold the values to run the sort on function filefunction(path, Name, Type, datemodified, Size){ this.Path = path; this.name = Name; this.type = Type; this.DateLastModified = datemodified; this.size = Size; } //creat your sort function function sortname(a, b) { var x = b.name; var y = a.name; return ((x < y) ? -1 : ((x > y) ? 1 : 0)); } //call the function after all other ifs at the end of the findfile function //if you want this to be dynamic then do an if like if(frmSearch.chk_sort_name.checked){ //place below code in these brackets} filepath.sort(sortname); for(i=0; i<x;i++){ result += '<TR' + ( ( toggle ) ? '' : ' BGCOLOR="#f0f0f0"' ) + '>' + '<TD NOWRAP><FONT CLASS="find">&nbsp;<A TARGET="_blank" HREF="' + filepath[i].Path + '">' + filepath[i].name + '</A>&nbsp;</FONT></TD>' + '<TD NOWRAP><FONT CLASS="find"> ' + filepath[i].type + ' </FONT></TD>' + '<TD NOWRAP><FONT CLASS="find"> '+ filepath[i].DateLastModified +' </FONT></TD>' + '<TD NOWRAP ALIGN="right"><FONT CLASS="find">&nbsp;' + toMetric( filepath[i].size ) + '&nbsp;</FONT></TD></TR>'; // Toggle the color toggle variable. toggle = !toggle;
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
How can ActiveXObject("Scripting.FileSystemObject") be used in Mozilla? Please reply soon..
Thanks in advance Megha Purkayastha
|
| Sign In·View Thread·PermaLink | 2.10/5 (10 votes) |
|
|
|
 |
|
 |
Hi!
Can i list the directorys also? I want to make a directory uploadar script. Its now exists some code? Can anyone help me? Thanx
-- modified at 9:03 Wednesday 21st June, 2006
|
| Sign In·View Thread·PermaLink | 1.50/5 (2 votes) |
|
|
|
 |
|
 |
hi did u got the answer for this. i am also getting the same error.. plz help me very urgent. send reply to this id vijay.shankarp@yahoo.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
you have to enable active x objects in your internet settings tools internet options security custom level ... prompt or enable all things activex .... its probably going to be the one that says "initialize unsafe activex scripts" set this to prompt just to be safe... if your on a intranet then you must do this in those settings as well.
hope this helps,
Jason
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
This script is very usefull but what changes i have to make in order to work on a remote server, in my server www.blahblah.com/docs for example. Thanks
|
| Sign In·View Thread·PermaLink | 2.25/5 (4 votes) |
|
|
|
 |
|
 |
Ok. This code is a client side scripting code with JScript. Simply you can make a asp file scripted with jscript and use the following code to execute on server side and browse scan and fetch File System structure on the own server. Rememer many of servers restict some ActiveX object activities for security reasons but I think you can test and if you have luck you can do
|
| Sign In·View Thread·PermaLink | 2.00/5 (5 votes) |
|
|
|
 |