Thanks for taking the time to read this.
My problem is below.
I have two directories with music in them. one on my C: the other on a removable drive. I use dir > list.txt to output a list of the contents of both folders. I want to build a program that will compare the two text files and show me what is in the C: and not in the H:
i have the GUI developed and some basic code, however, i am undersure how to do the actual comparision. Any help would be appreciated.
Many thanks | | kitsch Wednesday, December 14, 2005 6:46 PM | No problems, glad to help. To answer your directory control question: well, it depends on what you want to do with it and how you want to view it. You could use a directory control to view the data, which might be kid of fun (you could do neat things like display information about the files, add in code to act on those files (like create a menu item saying “Transfer to H:�and then support it in code, etc.). It you just want a report, well then a list is probably adequate Honestly, I haven’t actually used the directory control myself so I’m not clear on everything it can do.
What I’d probably do is at least display the files in a listview control (or some other UI), and set it for multi-selection �then I’d add a button that, when clicked, would copy the selected files in the listview to H:. Extra credit points for displaying both directories (the C:\ one and the H:\ one) in two listview (or whatever) controls, highlighting the differences between the two (say, red for files in C: and not H:, and blue for vice-versa), and having appropriate buttons to transfer them in either direction �that would be kind of cool, and would support the case where you’re actually moving music from one machine to the next via (for example) a flash card.
Regarding the input directory names: what I’d do is create an edit box for each, and put a button beside each that, when pressed, would bring up the file directory dialog (and populate the edit box with the result) so that the user could either type in the path or select it from a dialog.
--Matt--* | | Matthew Gertz MS Friday, December 16, 2005 12:01 AM | Hi, Kitsch,
So, assuming that the set of songs on H: are larger than the set of songs in C:, probably what I’d do (using VS2005) is read in the data from H into a list of strings (“Dim HList As List(Of String)�and “HList.Add(SomeHFilename)�, and then read in the data from C: -- I’d check to see if the item was already in the list (“if HList.BinarySearch(SomeCFilename) >= 0 Then…�, and if it wasn’t, then I’d add it to a second list which would end up containing everything on C: that wasn’t on H. There are other ways to do this, but basically you’ll have to create some sort of array to compare against.
However, I’d probably ditch the idea of doing dir > list.txt altogether and just read in the filelists directly from the operating system, to make this a one-step process. Something like
Dim CDirInfo As System.IO.DirectoryInfo
CDirInfo = My.Computer.FileSystem.GetDirectoryInfo("C:\somedirectory")
Dim CFiles() As System.IO.FileInfo = CDirInfo.GetFiles()
Dim MissingFiles As New List(Of String) ' or your favorites collection type, if not using VS2005
For Each CFile As System.IO.FileInfo In CFiles
If Not My.Computer.FileSystem.FileExists("H:\someother directory\" & CFile.Name) Then
MissingFiles.Add(CFile.Name) ' Or just Console.WriteLine(CFile.Name), or whatever
End If
' (…display MissingFiles to the user, etc�
Next
(You’d have to worry about duplicate names if subdirectories are involved, so you might want to check against partial paths rather than filenames, to distinguish between all of the covers of “Blue Suede Shoes�or whatever. To do this, simply use other members of the FileInfo class to get path information. You can also get other file information from FileInfo, to check sizes or whatnot. The directory names on C: and H: should also probably be passed in via arguments or from the GUI rather then hard-coded, but you get the idea.)
Hope this helps!
--Matt Gertz--*
VB Compiler Dev Lead | | Matthew Gertz MS Wednesday, December 14, 2005 8:53 PM | wow, thanks for that!
it certainly give me a good insight into the scope with which i have to work.
i'll do some more reading into it, cheers again! | | kitsch Thursday, December 15, 2005 1:13 AM | just had a little attempt to build it there.
one question - the sample code you provided, would i attach that to a tree directory control?
Also, i plan to use an input dialog to acquire the directory names from the user, and store this in a variable, and pass it to the GetDirectoryInfo method - should about right?
Cheers again for your help! | | kitsch Thursday, December 15, 2005 3:50 PM | (That should have read “assuming that the files on H: are a subset of the files on C:��sorry for the confusion.) | | Matthew Gertz MS Thursday, December 15, 2005 4:51 PM | No problems, glad to help. To answer your directory control question: well, it depends on what you want to do with it and how you want to view it. You could use a directory control to view the data, which might be kid of fun (you could do neat things like display information about the files, add in code to act on those files (like create a menu item saying “Transfer to H:�and then support it in code, etc.). It you just want a report, well then a list is probably adequate Honestly, I haven’t actually used the directory control myself so I’m not clear on everything it can do.
What I’d probably do is at least display the files in a listview control (or some other UI), and set it for multi-selection �then I’d add a button that, when clicked, would copy the selected files in the listview to H:. Extra credit points for displaying both directories (the C:\ one and the H:\ one) in two listview (or whatever) controls, highlighting the differences between the two (say, red for files in C: and not H:, and blue for vice-versa), and having appropriate buttons to transfer them in either direction �that would be kind of cool, and would support the case where you’re actually moving music from one machine to the next via (for example) a flash card.
Regarding the input directory names: what I’d do is create an edit box for each, and put a button beside each that, when pressed, would bring up the file directory dialog (and populate the edit box with the result) so that the user could either type in the path or select it from a dialog.
--Matt--* | | Matthew Gertz MS Friday, December 16, 2005 12:01 AM |
|