Click here to Skip to main content
13,055,047 members (53,548 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi, been doing VB and VBScript of 3 days now and I think it is time to ask for help, so help

Ok I need to be able to search for multipul file extensions, lets say xls and mdb (might be more) on a local machine with more than 1 local drive (no more than 3) and then export that to a file say xls or txt with the following information.

Name of file
Location of the file
Last accessed time

and if possible the machine name that was searched.

I have a bsic VBScript I have managed to write that lets me search a folder on my pc for txt files

strDir = "D:\USERDATA\RowellCJ\My Documents"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objDir = FSO.GetFolder(strDir)
Sub getInfo(pCurrentDir)
For Each aItem In pCurrentDir.Files
    If LCase(Right(Cstr(aItem.Name), 3)) = "txt" 
    Then wscript.Echo aItem.Name 
   End If
For Each aItem In pCurrentDir.SubFolders   
End Sub

and this VB code in Visual studio with help from books and google that runs on a folder and produces a report for me but

Imports System.IO
Public Class Form1
    Function IsMatch(ByVal FExt As String) As Boolean
        Dim AllowedExts() As String = {".xls", ".xlsx", ".mdb", ".accdb"}
        For Each Ext As String In AllowedExts 
            If FExt = Ext Then Return True
        Return False 
    End Function
    Sub GetNames(ByVal DirPath As String)
        Dim objFileInfo As FileInfo 
        Dim objDir As DirectoryInfo = New DirectoryInfo(DirPath)
        Dim objSubFolder As DirectoryInfo
        Dim finfo As FileInfo
        Cursor = Cursors.WaitCursor
            For Each objFileInfo In objDir.GetFiles()
                finfo = My.Computer.FileSystem.GetFileInfo(objFileInfo.FullName)
                If IsMatch(objFileInfo.Extension) 
Then  TextBox1.AppendText(objFileInfo.FullName & "," & objFileInfo.LastAccessTime.ToShortDateString & _
                                       "," & objFileInfo.LastAccessTime.ToShortTimeString & vbCrLf) 
                End If
            For Each objSubFolder In objDir.GetDirectories()
        Catch Ex As Exception
            TextBox1.AppendText("Error fetching file/sub-dir" & vbCrLf)
        End Try
        Cursor = Cursors.Default
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim StrPath As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) 
        Dim StrName As String = "\File_Audit_Of-" & System.Environment.MachineName & "-Date=" & _
        Now.ToShortDateString & "-Time=" & Now.ToShortTimeString & ".txt"         StrName = StrName.Replace("/", "-") 
        StrName = StrName.Replace(":", "-")
        Dim StrTemp As String = StrPath & StrName 
        TextBox1.Text = System.Environment.MachineName & vbCrLf         GetNames(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)) 
        Dim sw As New StreamWriter(StrTemp) 
        MsgBox("File saved as " & StrTemp) 
    End Sub
End Class

This runs on a folder and produces a report for me but how do I get this into a VBScript and do what I need as getting really confused and the more i get confused the harder it is becoming to see the answer.

Will keep going but advice and help will be really appricated

Posted 7-Dec-11 16:33pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You add VB code in a class and invoke it from VBScript.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 7 Dec 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100