Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VBScript
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)
getInfo(objDir)
Sub getInfo(pCurrentDir)
For Each aItem In pCurrentDir.Files
    If LCase(Right(Cstr(aItem.Name), 3)) = "txt" 
    Then wscript.Echo aItem.Name 
   End If
Next
For Each aItem In pCurrentDir.SubFolders   
	getInfo(aItem) 
Next
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
        Next
        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
        Try
            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
            Next
            For Each objSubFolder In objDir.GetDirectories()
                GetNames(objSubFolder.FullName)
            Next
        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) 
        sw.Write(TextBox1.Text) 
        sw.WriteLine() 
        sw.Close() 
        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
 
Chris
Posted 7-Dec-11 17:33pm

1 solution

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

Solution 1

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

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 520
1 Mathew Soji 335
2 BillWoodruff 260
3 OriginalGriff 215
4 Afzaal Ahmad Zeeshan 188
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,028
3 Manas Bhardwaj 4,539
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 7 Dec 2011
Copyright © CodeProject, 1999-2014
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