Ir para conteúdo
Fórum Script Brasil
  • 0

Fso


Gafanhoto

Pergunta

O código que eu to usando é esse:

--------------------------------------

<%

'

textoP = Request.Form("SearchText")

Const fsoForReading = 1

Dim objFile, objFolder, objSubFolder, objTextStream

Dim bolCase

dim strSearch

dim tStart, tLen

dim Cnt

Dim strExt, strFile, strContent, strRoot, strTag, strTitle

Dim lCount

function ExcludeRoot(strPath, strRootPath)

dim strReal

strReal=server.mappath(strRootPath)

if strPath="" then

ExcludeRoot=strRootPath

elseif strRootPath="" then

ExcludeRoot=strPath

elseif instr(1,strPath,strReal,1)=0 then

ExcludeRoot=""

else

ExcludeRoot=mid(strPath,instr(1,strPath,strReal,1)+len(strReal)+1)

end if

end function

function GetDescription(S) '//retrieves page description from <Meta Name="Description"> tag //

dim tStart, tLen, tDesc

tDesc=instr(1,(S),"name=""description""",1)

if tDesc>0 then

tStart=instr(tDesc+13,S,"content=",1)

if tStart>0 then

tLen=instr(tStart+9,S,">",1)-tStart-10

GetDescription=mid(S,tStart+9,tLen)

if instr(GetDescription,"<") then GetDescription=""

end if

end if

end function

'// Code starts here //

response.expires=-1

strFile = ".htm .html .txt" '// type the extensions you wish to search for //

strRoot = "..\clt\" '//change this to your root directory //

strTag = "<!--no search" '//put this tag into the pages you wish to exclude from search: <!--no search--> (or change as you wish) //

lCount=0 '//reset counter//

'// Get the user's input //

strSearch = Request.Form("SearchText") '// the search string //

If Request.Form("Case") = "on" Then bolCase = 0 Else bolCase = 1 '// case sensitive or not //

reqNumber = cint(Request.Form("rResults")) 'max number of results to be shown //

'// create objects //

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

Set objFolder = objFSO.GetFolder(Server.MapPath(strRoot))

'// Start searching //

if strSearch<>"" then

schSubFol(objFolder) '//search the root folder //

For Each objSubFolder in objFolder.SubFolders '// search any subfolders //

if InStr(1,objSubFolder.Name,"_vti_",1)=0 then '// skip system dirs created by Front Page //

schSubFol(objSubFolder)

if lCount>reqNumber then exit for '// if reached max number of results then stop //

end if

Next

end if

If lCnt=0 then Response.Write ("----------------") else Response.Write ("<B>----------------</B>")

'//clean up //

Set objFolder = Nothing

Set objFSO = Nothing

'// THAT'S IT //

'// HERE THE ACTUAL SEARCH IS BEING PERFORMED //

Function schSubFol(objFolder) '// return 1 if search is succesful, 0 otherwise //

schSubFol=0

For Each objFile in objFolder.Files

If Response.IsClientConnected Then

tStart=InstrRev(objFile.Name, ".",-1,1) '// find the last dot //

if tStart<>0 then strExt=mid(objFile.Name,tStart) else strExt="no ext" '// get the extension //

if Instr(1, strFile, strExt, 1)<>0 then '// check the extension //

Set objTextStream = objFSO.OpenTextFile(objFile.Path,fsoForReading, False)

If not (objTextStream.AtEndOfStream) then '// check if file is empty //

strContent = objTextStream.ReadAll '//read file contents //

If InStr(1, strContent, strTag, 1)=0 Then '// skip pages containing 'exclude' directive

If InStr(1, strContent, strSearch, bolCase) Then '// find an occurence of the search string //

tStart=InStr(1, strContent, "<TITLE>", 1)

if tStart>0 then '// Tag <title> is found //

tLen=InStr(1, strContent, "</TITLE>", 1) -tStart-7

strTitle = Mid(strContent, tStart+ 7, tLen)

if instr(strTitle,"<") or instr(strTitle,">") then strTitle="" '// in case there is an error in the page HTML

End if

if strTitle="" then strTitle = "Sem título"

sDesc=GetDescription(strContent) '// retrieve document description if available //

if sDesc="" then sDesc="..."

lCount = lCount + 1 '//increase counter//

'// write the results to the result page //

Response.Write "<p><dir><B><I>"& cstr(lCount) &"</I></B> - <A HREF=" & excluderoot(objFile.Path,strRoot) & "?palavra="& textoP &" target=_blank><font color=black>" & strTitle & "</A></i></b><BR>"

Response.write("<dir><font size='2'><br></font></dir>")

Response.Write "</FONT></I></dir></p>"

schSubFol = 1

End If '//search string

End if '//exclude check

End if '// file check //

objTextStream.Close

End If '// extension check //

End If '//client connected check

if lCount>reqNumber then exit for '//check if max number of records achieved

Next

strContent="" '// release some memory just in case //

Set objTextStream = Nothing '//destroy object//

End Function

%>

------------------------------------------------------

Ps: Desculpa, mas o CODEBOX não tá funcionando no fórum...

O que tá acontecendo é o seguinte: Vamos supor que eu digite a palavra PIS. Eu quero que coincida a palvra inteira, mas ao invés disse ele está como se fosse o LIKE. Ex: Eu digito PIS, ele acha PISo salarial, PISei num tomate, essas coisas..

Não sei o que alterar no código....

Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

  • 0

nossa esse codigo é muito grande... o uso do instr com mid resolve..

bom você pode adicionar um espaço antes e depois e adicionar para buscar PIS, PIS.

se o que quer for da forma que eu entendi ao ler seu post seria isto...

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      651,9k
×
×
  • Criar Novo...