FileManagement.vb 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. Imports System.Text
  2. Public Class FileManagement
  3. Implements System.Collections.IComparer
  4. Dim apppath As String = Application.StartupPath & "\"
  5. Dim ms As String = apppath & "MusicSorter\"
  6. Public Sub InitiateFolderSystem()
  7. 'If My.Computer.FileSystem.DirectoryExists(apppath & "MusicSorter\") = False Then
  8. 'My.Computer.FileSystem.CreateDirectory(apppath & "MusicSorter\")
  9. 'End If
  10. 'If My.Computer.FileSystem.DirectoryExists(ms & "Sorting") = False Then
  11. 'My.Computer.FileSystem.CreateDirectory(ms & "Sorting")
  12. 'End If
  13. End Sub
  14. Public Sub CreatSort(ByVal SortMethode As String)
  15. If My.Computer.FileSystem.DirectoryExists(ms & "Sorting\" & SortMethode) Then
  16. My.Computer.FileSystem.CreateDirectory(ms & "Sorting\" & SortMethode)
  17. End If
  18. End Sub
  19. Public Function Compare(ByVal info1 As Object, ByVal info2 As Object) As Integer Implements System.Collections.IComparer.Compare
  20. Dim FileInfo1 As System.IO.FileInfo = DirectCast(info1, System.IO.FileInfo)
  21. Dim FileInfo2 As System.IO.FileInfo = DirectCast(info2, System.IO.FileInfo)
  22. Dim Date1 As DateTime = FileInfo1.CreationTime
  23. Dim Date2 As DateTime = FileInfo2.CreationTime
  24. If Date1 > Date2 Then Return -1
  25. If Date1 < Date2 Then Return +1
  26. Return 0
  27. End Function
  28. Public Function ListByDate(ByVal Directory As String)
  29. If My.Computer.FileSystem.DirectoryExists(Directory) = False Then
  30. Return Nothing
  31. End If
  32. Dim DirectoryInfo As New System.IO.DirectoryInfo(Directory)
  33. Dim Files() As System.IO.FileInfo = DirectoryInfo.GetFiles()
  34. Array.Sort(Files, Me)
  35. Return Files
  36. End Function
  37. Function ReadFile(ByVal Filename As String)
  38. On Error Resume Next
  39. Dim code As String = Nothing
  40. If System.IO.File.Exists(Filename) = True Then
  41. Dim objReader As New System.IO.StreamReader(Filename, System.Text.Encoding.GetEncoding(950))
  42. Dim sb As New StringBuilder
  43. Do While objReader.Peek() <> -1
  44. code = objReader.ReadLine() & vbNewLine
  45. sb.AppendLine(code)
  46. Loop
  47. objReader.Dispose()
  48. Return sb.ToString
  49. Else
  50. Return Nothing
  51. End If
  52. End Function
  53. End Class