by satish & gopal (1 Submission)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 11th June 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)
a simple code to retrive the files of a directory by just supplying its directory name and it also compares the two file locationg in that
API Declarations
'create two list and three command buttons.
'goto projects-->references-->microsoftscriptingruntime , make enable and click OK button
Public filetext As String
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:" & Text1.Text
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
No comments have been posted about a simple code to retrive the files of a directory by just supplying its directory name and it also . Why not be the first to post a comment about a simple code to retrive the files of a directory by just supplying its directory name and it also .