12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- Imports System.Text
- Public Class FileManagement
- Implements System.Collections.IComparer
- Dim apppath As String = Application.StartupPath & "\"
- Dim ms As String = apppath & "MusicSorter\"
- Public Sub InitiateFolderSystem()
- 'If My.Computer.FileSystem.DirectoryExists(apppath & "MusicSorter\") = False Then
- 'My.Computer.FileSystem.CreateDirectory(apppath & "MusicSorter\")
- 'End If
- 'If My.Computer.FileSystem.DirectoryExists(ms & "Sorting") = False Then
- 'My.Computer.FileSystem.CreateDirectory(ms & "Sorting")
- 'End If
- End Sub
- Public Sub CreatSort(ByVal SortMethode As String)
- If My.Computer.FileSystem.DirectoryExists(ms & "Sorting\" & SortMethode) Then
- My.Computer.FileSystem.CreateDirectory(ms & "Sorting\" & SortMethode)
- End If
- End Sub
- Public Function Compare(ByVal info1 As Object, ByVal info2 As Object) As Integer Implements System.Collections.IComparer.Compare
- Dim FileInfo1 As System.IO.FileInfo = DirectCast(info1, System.IO.FileInfo)
- Dim FileInfo2 As System.IO.FileInfo = DirectCast(info2, System.IO.FileInfo)
- Dim Date1 As DateTime = FileInfo1.CreationTime
- Dim Date2 As DateTime = FileInfo2.CreationTime
- If Date1 > Date2 Then Return -1
- If Date1 < Date2 Then Return +1
- Return 0
- End Function
- Public Function ListByDate(ByVal Directory As String)
- If My.Computer.FileSystem.DirectoryExists(Directory) = False Then
- Return Nothing
- End If
- Dim DirectoryInfo As New System.IO.DirectoryInfo(Directory)
- Dim Files() As System.IO.FileInfo = DirectoryInfo.GetFiles()
- Array.Sort(Files, Me)
- Return Files
- End Function
- Function ReadFile(ByVal Filename As String)
- On Error Resume Next
- Dim code As String = Nothing
- If System.IO.File.Exists(Filename) = True Then
- Dim objReader As New System.IO.StreamReader(Filename, System.Text.Encoding.GetEncoding(950))
- Dim sb As New StringBuilder
- Do While objReader.Peek() <> -1
- code = objReader.ReadLine() & vbNewLine
- sb.AppendLine(code)
- Loop
- objReader.Dispose()
- Return sb.ToString
- Else
- Return Nothing
- End If
- End Function
- End Class
|