问题描述
您好,现在已经进行了3天的VB和VBScript,我认为是时候寻求帮助了,所以帮助
好吧,我需要能够搜索multipul文件扩展名,在具有多个本地驱动器(不超过3个)的本地计算机上说xls和mdb(可能更多),然后将其导出到文件中,例如xls或txt包含以下信息.
文件名
文件的位置
上次访问时间
以及如果可能的话,搜索的机器名称.
我已经编写了一个基本的VBScript,可以在我的PC上的一个文件夹中搜索txt文件
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
以及Visual Studio中的此VB代码,在书籍和Google的帮助下运行在文件夹上,并为我生成报告,但
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
它在一个文件夹上运行并为我生成报告,但是如何将其放入VBScript中并做我真正困惑时需要做的事情,而我越是困惑,就越难找到答案.
会继续前进,但建议和帮助会得到真正的应用
Chris
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
推荐答案
这篇关于在PC上按扩展名查找文件并导出到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!