Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Retrieve Files by Giving Directory Name
Author:
P.SATISH & P.GOPALl
E-mail:
Click to e-mail author
Submitted:
11/6/2003
Version:
VB6
Compatibility:
VB6
Category:
File Manipulation
Views:
19603
This is a simple code which retrieves the files into list boxes by just supplying any directory in the textbox. It also compares the two files which you select from those listboxes by just clicking a button.
Declarations:
'add these below contents to your form 'textboxes - 1 'command buttons - 3 'listboxes - 2 'goto project-->references-->microsoftscriptingruntime 'enable--->press O.K. Button Public filetext As String
Code:
Private Sub Command2_Click() Dim fso As New FileSystemObject myfoldertext = "c:\" & Text1.Text Call get_all_directory_files(fso.GetFolder(myfoldertext)) Set fso = Nothing End Sub Public Sub get_all_directory_files(ByVal tfolder As Folder) Dim objfile As File Dim objfolder As Folder Dim fso As New FileSystemObject Dim j As Integer If tfolder <> "" Then For Each objfile In tfolder.Files 'do the stuff we want with the files 'filetext = filetext + objfile + vbNewLine List1.AddItem objfile 'List1.List (List1.ListIndex) Next j = List1.ListCount For Each objfolder In tfolder.SubFolders Call get_all_directory_files(objfolder) Next Set fso = Nothing End If End Sub Private Sub Command3_Click() Dim fso As New FileSystemObject 'Dim qw As String 'qw = Text1.Text myfoldertext1 = "c:\ches\qa" Call get_all_directory_files2(fso.GetFolder(myfoldertext1)) Set fso = Nothing End Sub Public Sub get_all_directory_files2(ByVal tfolder As Folder) Dim objfile1 As File Dim objfolder As Folder Dim fso As New FileSystemObject Dim i As Integer If tfolder <> "" Then For Each objfile1 In tfolder.Files 'do the stuff we want with the files ' filetext = filetext + objfile1 + vbNewLine List2.AddItem objfile1 'List2.List (List2.ListIndex) Next i = List2.ListCount For Each objfolder In tfolder.SubFolders Call get_all_directory_files2(objfolder) Next Set fso = Nothing End If End Sub Private Sub Command4_click() Dim objWord Dim objScript Dim strDocA Dim strDocB Dim fContinue 'Const vbExclamation = 48 ' For j = 0 To List1.ListCount - 1 If List1.Selected(j) = True Then strDocA = List1.List(j) End If Next 'InputBox("Enter complete path first doc", "Compare") ' For i = 0 To List2.ListCount - 1 If List2.Selected(i) = True Then strDocB = List2.List(i) End If Next 'InputBox("Enter complete path second doc", "Compare") ' Assume that user entered valid file paths fContinue = True ' Test file paths to DocA and DocB for validity. ' -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Set objScript = CreateObject("Scripting.FileSystemObject") fContinue = objScript.FileExists(strDocA) fContinue = objScript.FileExists(strDocB) Set objScript = Nothing If fContinue = False Then MsgBox "Invalid File Paths", vbExclamation, "Error" Else ' Only continue if user has typed text into InputBox. Set objWord = CreateObject("Word.Application") objWord.Documents.Open strDocA objWord.ActiveDocument.Compare strDocB objWord.Visible = True Set objWord = Nothing End If End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement