File Search
Author |
Message |
DIIST
|
Posted: Sun May 06, 2007 2:46 pm Post subject: File Search |
|
|
A simple file search engine. Right now it only displays all the results in a text window so you can cut and past the directory into the address bar of a window browser to find the file. It checks all the drives but does not actually read inside the file nor does it go in system folder and search. Try it out.
I was a bit to lazy to show a progress bar so if you want to see the progress of the search do this:
Run-> Show Debugger Menu
Debugger->Show Allocated Objects
Turing: |
setscreen ("text:25;80,nobuttonbar,title:File Search")
var key : string := ""
var root : string := ""
procedure sizeStr (num : nat4)
if num > 1000000000 then
put (num / 1000000000) : 0 : 2, "Gb"
elsif num > 1000000 then
put (num / 1000000) : 0 : 2, "Mb"
elsif num > 1000 then
put (num / 1000) : 0 : 2, "Kb"
else
put num, "b"
end if
end sizeStr
procedure search (dir : string)
var file : string
var stream, size, atribute, fTime : int
stream := Dir.Open (dir )
if stream > 1 then
loop
Dir.GetLong (stream, file, size, atribute, fTime )
exit when file = ""
if index (file, key ) > 0 then
put "----------"
put "File Name: ", file
put "Size: " ..
sizeStr (size )
put "Last Accesed: ", Time.SecDate (fTime )
put "Directory: ", dir
end if
if index (file, ".") = 0 and not (bits (atribute, 5) = 1) then %Makes Sure its a floder and checks if its not a system folder
search (dir + file + "\\") %Before opening the directory
end if
end loop
Dir.Close (stream )
end if
end search
put "******************************************************************************"
put "* File Search Engine *"
put "* By Thuvs *"
put "******************************************************************************"
put "Enter a search key:"
loop %You may choose to remove this, i only put it there becasue there are some morons that put "." as the key.
%You can guess what will happen.
get key
exit when length (key ) > 3
put "Key is very small and will thorw off millions of reasults. Please enter a key size that is greater than three characters:"
end loop
for i : 0 .. 25
search (chr (i + 65) + ":" + "\\")
end for
put "-------------"
put "End of Search"
|
If it doesn't work post the OS your on(Might have trouble with 98), and provide a minimal description. I'm going to plan to extend this to make a GUI search dialog soon. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
LaZ3R
|
Posted: Mon May 07, 2007 7:27 pm Post subject: Re: File Search |
|
|
Hehe, Very neat program! I tried something like it a while ago but it involved a slightly different method. It was just a few lines longer than yours so good job! |
|
|
|
|
|
DIIST
|
Posted: Tue May 08, 2007 5:47 am Post subject: Re: File Search |
|
|
LaZ3R wrote:
Hehe, Very neat program! ) I tried something like it a while ago but it involved a slightly different method. It was just a few lines longer than yours so good job! D
When i originally made this program, it was a lot of lines, used embedded loops. Not only was it ugly an embarsing to look at, it was also really slow. Dosnt even check the other available drives on the computer. Here is the sample.
Turing: |
/*
Name: Thuvarrakan Ruban
Date: Feburary 12, 2006
Purpose: Search Engine, search through files and folders for a specific file or format!!!
*/
type folder :
record
pathname : string
stream : int
end record
/*****************************************************************/
/********************Functions And Procedures*********************/
/*****************************************************************/
/*
iniF
Purpose: Initilizes
Accepts:filename:string-name of filefolder
x-array of prevous folders
Modifies: x-array to account for the new folder
Retruns: True or False if an error occures or not while opening a folder!!!!
Note: It also opens the the directory or folder here!!!
*/
function iniF (filename : string, var x : array 0 .. * of folder ) : boolean
x (upper (x )).pathname := x (upper (x ) - 1).pathname + filename + "/"
x (upper (x )).stream := Dir.Open (x (upper (x )).pathname )
if Error.Last = 0 then
result false
else
result true
end if
end iniF
/*
stripname
Purpose:To Give A name of a file from a pathway!!!!
Accepts:x-string:holds pathname!!!
Retruns: Name of file!!!!
*/
function stripname (x : string) : string
var len := length (x )
var temp : string := ""
var str : string := ""
if x (len ) = "/" then
len - = 1
end if
for decreasing i : len .. 1
exit when x (i ) = "/"
temp + = x (i )
end for
for decreasing i : length (temp ) .. 1
str + = temp (i )
end for
result str
end stripname
/*
getinfo
Purpose: Gets User Information!!!!
Accepts: x:string:-the main string
y:the little string which is supposed to be hilighted in the main string
Outputs: The string with its necerasy highlights
*/
procedure highlight (x, y : string)
var start : int := index (x, y )
for i : 1 .. length (x )
if i >= start and i < length (y ) + start then
colour (14)
put x (i ) ..
else
colour (10)
put x (i ) ..
end if
if i >= start + length (y ) then
if index (x ((start + length (y )) .. *), y ) not= 0 then
start + = (length (y ) - 1) + index (x ((start + length (y )) .. *), y )
end if
end if
end for
colour (10)
put "\n"
end highlight
/*
printResults
Purpose: Prints the results
Accepts:x:array of string, the pathname for all the results!!!
Inputs:Key board character to continue towards the next result!!!
Outputs: Each Result!!!
*/
procedure printResults (x : array 0 .. * of string, search : string)
var e : string (1)
cls
if upper (x ) = 0 then
put "Turing Could Not find what you where searching for!\nNO RESULTS MATCH"
else
put "Turing has found ", upper (x ), " result(s)!"
put "\nPress any Key To Continue..."
getch (e )
cls
for i : 0 .. upper (x ) - 1
cls
put "Viewing ", i + 1, " of ", upper (x ), " :\n"
put "Name: " ..
highlight (stripname (x (i )), search )
put "Pathname: "
highlight (x (i ), search )
if i < upper (x ) - 1 then
put "\nPress any key to continue!"
else
put "\nThank you for using Turing Search Engine!!!"
end if
getch (e )
end for
end if
end printResults
/*
getinfo
Purpose: Gets User Information!!!!
Accepts: x:string:-what the user wants to search!!!
y:int:-depth of search!
Modifies:x & y: with what the user entered
Inputs:The user informaion for the search
Outputs: The silly questions and the error messages
*/
proc getinfo (var x : string, var y : int)
put "\n\n\nPlease enter the file name or extension you wish to search: " ..
loop
get x : *
exit when length (x ) > 2
put "\nName or extension is too small and may triger 100(s) of results!!!"
put "\nPlease enter again: " ..
end loop
cls
put "Please enter the depth of search, or how many \nsubdirectories Turing Should search beneath!"
put "Please enter between (5-7)"
loop
get y
exit when y < 8
put "Error, to large,the search will take too long!!!\nPlease Enter Again"
end loop
end getinfo
/*
SEARCH
Purpose: The so called search engine
Accepts: search-string-what the procedure is searching withen the directories
maxtreesize-int-the depth of the search!!!
*/
procedure SEARCH (search : string, maxtreesize : int)
var tree : flexible array 0 .. 0 of folder
var results : flexible array 0 .. 0 of string
var fileName : string
%Some Preprocedural Stuff
tree (0).pathname := "C:/"
tree (0).stream := Dir.Open (tree (0).pathname )
assert tree (0).stream > 0
loop
fileName := Dir.Get (tree (upper (tree )).stream )
%Closes a directory if an empty string is returned
if fileName = "" then
if upper (tree ) not= 0 then
Dir.Close (tree (upper (tree )).stream )
new tree, upper (tree ) - 1
else
exit
end if
end if
%Checks to see if file name matches the search name in any way,if it does,it puts it as a result!!!!
if index (fileName, search ) > 0 and upper (tree ) <= maxtreesize then
results (upper (results )) := tree (upper (tree )).pathname + fileName
new results, upper (results ) + 1
end if
%Checks for folders to search beneath!!!!
if index (fileName, ".") = 0 and upper (tree ) <= maxtreesize then %If there is no extension it assumes its a folder!
new tree, upper (tree ) + 1
if iniF (fileName, tree ) then
new tree, upper (tree ) - 1 %Destroies if there was a faileur!
end if
end if
end loop
Dir.Close (tree (0).stream ) %Closes the main directory
printResults (results, search )
new results, 0 %Frees Up resources
end SEARCH
/*****************************************************************/
/***************End of Functions And Procedures*******************/
/*****************************************************************/
/******************************************************/
/*******************Main Program***********************/
/******************************************************/
setscreen ("graphics:640;480,nobuttonbar,title:Created By: Thuvs R")
var name : string := ""
var depth : int := 0
drawfill (0, 0, 7, 7)
colour (10)
colourback (7)
put "Welcome to Turing Search Engine!"
put "This program searches your HD for a specific file!"
put "If you are not using windows please close this aplication!"
put "*Hidden folder and restricted folders are not scaned!"
getinfo (name, depth )
cls
put "Searching..."
SEARCH (name, depth )
/******************************************************/
/*****************End of Main Program******************/
/******************************************************/
|
This was in grade 10 you shouldn't expect much.
On the plus side it has its own functionality like coloring the search key with the text, and other lame stuff. |
|
|
|
|
|
Carey
|
Posted: Tue May 08, 2007 8:28 am Post subject: Re: File Search |
|
|
Wow. Talk about an ugly brute force method. Looks like something i would have done if i was trying to make a search program. the recursive solution is waaaaaaaaay better. (in length, looks and funtionality) |
|
|
|
|
|
|
|