Search script

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
JordyDB
Posts: 5
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Tue Apr 24, 2012 11:22 pm

Search script

Post by JordyDB »

Can someone help me with making this script, it's completely new for me:

Each night at 3 o'clock the script should run.
When it runs it has to search on a variable (wich comes out of a database) in all the files (content and name) of the C-drive.
The filter should be:
(Sample) OR (SampleID AND Staining) OR (SampleID AND Staining)
All the founded files should be putten in a table (or in case that doesn't work in a text file) with the attributes date modified, date created, Titel, Path, Owner, Type

Thanks in advance.

User avatar
JordyDB
Posts: 5
Joined: Tue Apr 24, 2012 11:22 pm

Search script

Post by JordyDB »

Can someone help me with making this script, it's completely new for me:

Each night at 3 o'clock the script should run.
When it runs it has to search on a variable (wich comes out of a database) in all the files (content and name) of the C-drive.
The filter should be:
(Sample) OR (SampleID AND Staining) OR (SampleID AND Staining)
All the founded files should be putten in a table (or in case that doesn't work in a text file) with the attributes date modified, date created, Titel, Path, Owner, Type

Thanks in advance.

jvierra
Posts: 14444
Joined: Tue May 22, 2007 9:57 am
Contact:

Search script

Post by jvierra »

Can you post your script? What errors are you geting? What is the isse you are trying to solve?

If you do not know how to start look in the script sharing section for scripts that do most of what you want and start there.

User avatar
JordyDB
Posts: 5
Joined: Tue Apr 24, 2012 11:22 pm

Search script

Post by JordyDB »

Can you post your script? What errors are you geting? What is the isse you are trying to solve?

If you do not know how to start look in the script sharing section for scripts that do most of what you want and start there.
I don't have a script yet, because I don't find any usefull scripts.

User avatar
JordyDB
Posts: 5
Joined: Tue Apr 24, 2012 11:22 pm

Search script

Post by JordyDB »

I guessit is time for you to start writing a script. Post back with any ptoblems.

I would say tht ther are at last 2 dozen script in the sharing section that can be used as startere. I know becuse I put many of them in ther myself.

Use the 'advanced search' to find them.
Can't find a script in the vbscript sharing section. Tried keywords 'search' 'content' 'word' 'file'...

User avatar
JordyDB
Posts: 5
Joined: Tue Apr 24, 2012 11:22 pm

Search script

Post by JordyDB »

Imports System.IOImports Microsoft.Office.InteropPartial Class _Default Inherits System.Web.UI.Page Dim position As Integer = 1 Public Sub GetFiles(ByVal path As String) If File.Exists(path) Then ' This path is a file ProcessFile(path) ElseIf Directory.Exists(path) Then ' This path is a directory ProcessDirectory(path) End If End Sub Public Shared Function GetTextFromPDF(PdfFileName As String) As String Dim oReader As New iTextSharp.text.pdf.PdfReader(PdfFileName) Dim sOut = "" For i = 1 To oReader.NumberOfPages Dim its As New iTextSharp.text.pdf.parser.SimpleTextExtractionStrategy sOut &= iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(oReader, i, its) Next Return sOut End Function ' Process all files in the directory passed in, recurse on any directories ' that are found, and process the files they contain. Public Sub ProcessDirectory(ByVal targetDirectory As String) ' Process the list of files found in the directory. Dim fileEntries As String() = Directory.GetFiles(targetDirectory) For Each fileName As String In fileEntries ProcessFile(fileName) Next ' Recurse into subdirectories of this directory. Dim subdirectoryEntries As String() = Directory.GetDirectories(targetDirectory) For Each subdirectory As String In subdirectoryEntries ProcessDirectory(subdirectory) Next End Sub ' Insert logic for processing found files here. Public Sub ProcessFile(ByVal path As String) Dim fi As New FileInfo(path) 'read file text Dim fso, f, filespec fso = CreateObject("Scripting.FileSystemObject") filespec = path Dim tekens As String tekens = path.ToString.Substring(path.LastIndexOf("") + 1, 2) f = fso.OpenTextFile(filespec, 1) ' Read line by line until end of file Dim tekst As String Dim soort As String = filespec.ToString.Substring(filespec.Length - 3, 3) Dim soort2 As String = filespec.ToString.Substring(filespec.Length - 4, 4) If (tekens = "~$") Then Else If (soort = "PDF") Then tekst = GetTextFromPDF(path) Else If (soort = "doc" Or soort2 = "docx") Then 'Dim appWord As New Word.Application 'Dim docWord As New Word.Document 'docWord = appWord.Documents.Open(path) 'docWord.ActiveWindow.Selection.WholeStory() 'docWord.ActiveWindow.Selection.Copy() 'appWord.ActiveDocument.Close() Dim word As New Word.Application() Dim doc As New Word.Document() Dim missing As Object = System.Type.Missing doc = word.Documents.Open(path, missing, missing, missing, missing, missing, _ missing, missing, missing, missing, missing, missing, _ missing, missing, missing, missing) doc.Activate() tekst = doc.Content.Text word.Documents.Close() word.Quit() 'For Each docRange As Word.Range In doc.Words ' If docRange.Text.Trim().Equals(searchtxt.Text, StringComparison.CurrentCultureIgnoreCase) Then ' docRange.HighlightColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdDarkYellow ' docRange.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdWhite ' End If 'Next Else If (soort = "xls" Or soort2 = "xlsx") Then Dim excel As New Excel.Application() Dim book As New Excel.Workbook() Dim sheet As New Excel.Worksheet() Dim missing As Object = System.Type.Missing book = excel.Workbooks.Open(path, missing, missing, missing, missing, missing, _ missing, missing, missing, missing, missing, missing, _ missing, missing, missing) sheet = book.Worksheets(1) sheet.Activate() tekst = sheet.Content.Text excel.Workbooks.Close() excel.Quit() 'For Each docRange As Word.Range In doc.Words ' If docRange.Text.Trim().Equals(searchtxt.Text, StringComparison.CurrentCultureIgnoreCase) Then ' docRange.HighlightColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdDarkYellow ' docRange.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdWhite ' End If 'Next Else Do While Not f.AtEndOfStream 'Response.Write(f.ReadLine & "<br />") tekst += f.ReadLine + " " Loop End If End If If (tekst.Contains(searchtxt.Text)) Then Response.Write("File Number " + position.ToString() + ". Path: " + path + " <br />") Response.Write(tekst) position += 1 End If End If End If f.Close() 'Search in file if word exists End Sub Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load 'GetFiles("C:UsersdbljorDesktoptestsearchfiles") End Sub Protected Sub btnsearch_Click(sender As Object, e As System.EventArgs) Handles btnsearch.Click GetFiles("C:UsersdbljorDesktoptestsearchfiles") End SubEnd Class

Locked