Click here to Skip to main content
16,005,491 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: module - what is this Pin
Luc Pattyn10-Aug-07 3:07
sitebuilderLuc Pattyn10-Aug-07 3:07 
QuestionDataGridView Column accept Numbers Only ? Pin
kindman_nb8-Aug-07 15:32
kindman_nb8-Aug-07 15:32 
AnswerRe: DataGridView Column accept Numbers Only ? Pin
Trupti Mehta8-Aug-07 21:42
Trupti Mehta8-Aug-07 21:42 
GeneralRe: DataGridView Column accept Numbers Only ? Pin
kindman_nb9-Aug-07 4:46
kindman_nb9-Aug-07 4:46 
QuestionHow to handle semi global variables Pin
Blizzardice8-Aug-07 10:20
Blizzardice8-Aug-07 10:20 
AnswerRe: How to handle semi global variables Pin
Christian Graus8-Aug-07 17:40
protectorChristian Graus8-Aug-07 17:40 
GeneralRe: How to handle semi global variables Pin
Blizzardice9-Aug-07 4:16
Blizzardice9-Aug-07 4:16 
QuestionComparing directories using VB.NET [modified] Pin
Ravi Mahavrathayajula8-Aug-07 9:12
Ravi Mahavrathayajula8-Aug-07 9:12 
I need a small help with a piece of code in VB.NET, that I am not getting right. I am trying to compare two directories, that have subdirectories containing files. I will have to compare both the directories and find out which subdirectories are the same (subdirectories having same files) and which subdirectories are different.

The code works fine till it gets into the respective two main directories and fetches the subdirectories present in them and also the files present in each of those subdirectories.

The problem I am facing is that the looping seems to be incorrect, which I am unable to debug. It doesn't compare all the subdirectories I think I am not getting the logic to proceed furthur. It breaks after one subdirectory. I will be very grateful, if anyone of you can assit me with the logic.

The code I have written is as below.


Dim file1byte As Integer
Dim file2byte As Integer
Dim fs1 As FileStream
Dim fs2 As FileStream

Dim path1 As String = mats.GetSetting("UnpackLocation") 'Directory 1 location
Dim getdir1 As String() = Directory.GetDirectories(path1)
Dim diren1 As System.Collections.IEnumerator
diren1 = getdir1.GetEnumerator
diren1.MoveNext() 'Points to the first subdirectory of Directory 1

Dim path2 As String = mats.GetSetting("path2") 'Directory 2 location
Dim getdir2 As String() = Directory.GetDirectories(path2)
Dim diren2 As System.Collections.IEnumerator
diren2 = getdir2.GetEnumerator
diren2.MoveNext() 'Points to the first subdirectory of Directory 2

Dim dirUpack1 As String() = Directory.GetFiles(diren1.Current) 'Gets the Files from the first subdirectory of Directory 1
Dim en1 As System.Collections.IEnumerator
en1 = dirUpack1.GetEnumerator
en1.MoveNext() 'Points to the first file in the subdirectory

Dim dirUpack2 As String() = Directory.GetFiles(diren2.Current) 'Gets the Files from the first subdirectory of Directory 2
Dim en2 As System.Collections.IEnumerator
en2 = dirUpack2.GetEnumerator
en2.MoveNext() 'Points to the first file in the subdirectory

Do
diren2.Reset()
diren2.MoveNext()
Do
en1.Reset()
en1.MoveNext()
Do
en2.Reset()
en2.MoveNext()
Do
' Determine if the same file was referenced two times.
If (en1.Current.ToString() = en2.Current.ToString()) Then
mats.ResultsLog.WriteError("Same File has been referenced Again!")
Exit Sub
End If
' Open the two files.
Console.WriteLine(en1.Current.ToString())
Console.WriteLine(en2.Current.ToString())
fs1 = New FileStream(en1.Current.ToString(), FileMode.Open)
fs2 = New FileStream(en2.Current.ToString(), FileMode.Open)
' Check the file sizes. If they are not the same, the files
' are not equal.
If (fs1.Length = fs2.Length) Then
Do
' Read one byte from each file.
file1byte = fs1.ReadByte()
file2byte = fs2.ReadByte()
Loop While ((file1byte = file2byte) And (file1byte <> -1))
' Close the files.
fs1.Close()
fs2.Close()
If ((file1byte - file2byte) = 0) Then
Console.WriteLine("The files are Same.")
GoTo jump1
Else
Console.WriteLine("The files are not Same.")
End If
Else
fs1.Close()
fs2.Close()
Console.WriteLine("The files are not Same.")
End If
' Return the success of the comparison. "file1byte" is
' equal to "file2byte" at this point only if the files are
' the same.
Loop While en2.MoveNext() = True
jump1: Loop While en1.MoveNext() = True
Loop While diren2.MoveNext() = True
Loop While diren1.MoveNext() = True

We will have to see if all the files in both the subdirectories are same, and if they are the same then Print that the SUB-DIRECTORIES are also same.

-- modified at 16:10 Wednesday 8th August, 2007
AnswerRe: Comparing directories using VB.NET Pin
Ravi Mahavrathayajula9-Aug-07 2:30
Ravi Mahavrathayajula9-Aug-07 2:30 
GeneralRe: Comparing directories using VB.NET Pin
MartyK20079-Aug-07 2:46
MartyK20079-Aug-07 2:46 
GeneralRe: Comparing directories using VB.NET Pin
Ravi Mahavrathayajula14-Aug-07 3:54
Ravi Mahavrathayajula14-Aug-07 3:54 
GeneralRe: Comparing directories using VB.NET Pin
MartyK200714-Aug-07 4:10
MartyK200714-Aug-07 4:10 
QuestionKeyDown ... Enter , System do Beep Pin
kindman_nb8-Aug-07 8:30
kindman_nb8-Aug-07 8:30 
AnswerRe: KeyDown ... Enter , System do Beep Pin
The ANZAC8-Aug-07 13:03
The ANZAC8-Aug-07 13:03 
GeneralRe: KeyDown ... Enter , System do Beep Pin
kindman_nb8-Aug-07 14:48
kindman_nb8-Aug-07 14:48 
QuestionPrint of pdf file to network printer fails Pin
Nick De Decker8-Aug-07 8:23
Nick De Decker8-Aug-07 8:23 
QuestionTabindex Problems Pin
programmervb.netc++8-Aug-07 7:16
programmervb.netc++8-Aug-07 7:16 
AnswerRe: Tabindex Problems Pin
Luc Pattyn8-Aug-07 7:39
sitebuilderLuc Pattyn8-Aug-07 7:39 
AnswerRe: Tabindex Problems Pin
Tom Deketelaere8-Aug-07 21:10
professionalTom Deketelaere8-Aug-07 21:10 
GeneralRe: Tabindex Problems Pin
programmervb.netc++9-Aug-07 4:03
programmervb.netc++9-Aug-07 4:03 
GeneralRe: Tabindex Problems Pin
Tom Deketelaere9-Aug-07 4:24
professionalTom Deketelaere9-Aug-07 4:24 
AnswerRe: Tabindex Problems Pin
i gr89-Aug-07 8:44
i gr89-Aug-07 8:44 
QuestionUpdating a database when an application goes online Pin
steve_rm8-Aug-07 6:32
steve_rm8-Aug-07 6:32 
AnswerRe: Updating a database when an application goes online Pin
Kschuler8-Aug-07 7:55
Kschuler8-Aug-07 7:55 
QuestionEntering new Address group in Outlook Express thru VB Pin
Xandip8-Aug-07 2:54
Xandip8-Aug-07 2:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.