Hi!
Does anyone know a searchscript to create a javascript file-search.
I want it to be able to search for a specific filename in a folder INCLUDING
its sub-folders.
I know there is a way to search a folder for a file but not its sub-folders, here
is what I got:
function findFile(Npath){
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fold = fso.GetFolder(Npath);
FileEnum = new Enumerator(fold.files);
for (; !FileEnum.atEnd(); FileEnum.moveNext()) {
document.editor.originfile.value += FileEnum.item().Name;
//When it finds the file I want it to store its path
if(FileEnum.item().Name == document.editor.showfile.value)
document.editor.originfile.value = FileEnum.item().Path;
}
}
This function looks through the mainfolder that you give
as parameter but not its sub-folders, when I tried to come
up with a algorithm for going through each subfolder, my
head started to hurt =). Is there a neat way to do it?
Thx
7 7358
Welcome to TSDN!
I think SubFolders (instead of "files") should contain the sub-directories.
Changed thread title (a bit more detail)
Thx for the reply!
But this doesn't work as I want it to.
If I change:
FileEnum = new Enumerator(fold.files);
to
FolderEnum = new Enumerator(fold.SubFolders);
All it does is list the subfolders in the main-folders and not the
the subfolders of the subfolders etc...
I want it to look for the file in the main-folder, sub-folders, the sub-sub-folders =
all folders in the path I've specified as paramter, is it possible?
I know I must create a recursive function, i.e. a function that looks through a
folder, looks at the files there, then takes the next subfolder and calls itself
again. The súbfolder's relative path needs to be stored in an array I guess, but I
don't feel that smart this early in the morning, and this must have been done a
thousand times before, but I can't find any algorithm on google. Does anyone
here know of one?
I know I must create a recursive function, i.e. a function that looks through a
folder, looks at the files there, then takes the next subfolder and calls itself
again. The súbfolder's relative path needs to be stored in an array I guess, but I
don't feel that smart this early in the morning, and this must have been done a
thousand times before, but I can't find any algorithm on google. Does anyone
here know of one?
You're on the right track. Having never worked with the filesystem object, I can only give you hints. You'd get the files in each folder/sub-folder. Then on each iteration, recursively call the same function which would again get the files and the sub-folders and so on until they were no sub-folders left. You would call the function using the path of the sub-folder. Since you're just searching, you can break out as soon as you find a match.
Woooo!
With quite a lot tea-drinking and weird background-music, I solved
the algorithm that checks all files in all subfolders of a folder, here
it is: -
function findFile(PathArray, itr, nextFree){
-
var newitr = nextFree;
-
var fso = new ActiveXObject("Scripting.FileSystemObject");
-
var fold = fso.GetFolder(PathArray[itr]);
-
FileEnum = new Enumerator(fold.files);
-
FolderEnum = new Enumerator(fold.SubFolders);
-
document.editor.originfile.value = "NOT FOUND!";
-
-
for(; !FileEnum.atEnd(); FileEnum.moveNext()){
-
document.editor.originfile.value += "F+" + FileEnum.item().Name;
-
if(FileEnum.item().Name == document.editor.showfile.value){
-
document.editor.originfile.value = "FOUND!";
-
return true;
-
}
-
}
-
for (; !FolderEnum.atEnd(); FolderEnum.moveNext()) {
-
PathArray[newitr] = FolderEnum.item().Path;
-
document.editor.originfile.value += "D+" + FolderEnum.item().Name;
-
newitr++;
-
}
-
findFile(PathArray, itr+1, newitr);
-
}
-
nextFree is the next free spot in the array of paths, so that a child of the
recursive function doesn't write over a place in the array which its parent
has written to. (Don't know if child and parent is the right terminology)
Woooo!
With quite a lot tea-drinking and weird background-music, I solved
the algorithm that checks all files in all subfolders of a folder
Excellent! Thanks for sharing.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ben |
last post by:
Greetings,
I am looking for a way to search for and delete files based on a pattern
mask. For example, the search method would find all files matching a
certain pattern containing wildcards (e.g....
|
by: Les Juby |
last post by:
A year or two back I needed a search script to scan thru HTML files
on a client site. Usual sorta thing. A quick search turned up a
neat script that provided great search results. It was fast,...
|
by: mm |
last post by:
Can someone with Win 2K please help me here. Best yet, can
some MVP duplicate it and report it to MS. I can't find
any reference to this issue on the Web, or in MS Knowledge
Base.
I have been...
|
by: Roomy |
last post by:
Guys,
I'd love if any of you can help me with this one.
I need a script that will take out the words Error,
Warning, and Aborted from a 12mb text file and into a new
text file after running the...
|
by: Philip Wagenaar |
last post by:
How do I search for a directory on a windows xp machine
and delete the directory including all subfolders and
files in them?
|
by: Joris De Groote |
last post by:
Hi,
I have a program that must look in in certain folder and take out every file
(also the files in subfolders). Now it's no problem to do this with a few
for's and if's. However, I don't know...
|
by: Bigrabid |
last post by:
Howdy,
I have an access database that I use to keep track of projects that my
group is working on. There are a number of files associated with any
one project, so I have as a parent to
, which...
|
by: =?Utf-8?B?UGVycmlud29sZg==?= |
last post by:
Not sure where to post this...
Found some interesting behavior in Windows Search (Start =Search =All
files and folders =search for "A word or phrase in the file:"). This
applies to XP and maybe...
|
by: =?Utf-8?B?QnJ5YW4=?= |
last post by:
Hello group.
I've migrated from Win 2003 server to Win 2008 server.
I've been banging my head agaist a wall for several days now trying to
figure this out.
I have the following script that will...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |