md5 hash von datei code problem

  • VB.NET

Es gibt 6 Antworten in diesem Thema. Der letzte Beitrag () ist von thefiloe.

    md5 hash von datei code problem

    HEY
    ich hab ne liste mit pfaden zu verschiedenen dateien, und will davon hash werte haben, der erste funktioniert ja noch, aba bei den anderen kommt da immer "illegales zeichen im pfad"
    code:
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Public Function MD5FileHash(ByVal sFile As String) As String
    2. Dim MD5 As New MD5CryptoServiceProvider
    3. Dim Hash As Byte()
    4. Dim Result As String = ""
    5. Dim Tmp As String = ""
    6. Dim FN As New FileStream(sFile, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
    7. MD5.ComputeHash(FN)
    8. FN.Close()
    9. Hash = MD5.Hash
    10. For i As Integer = 0 To Hash.Length - 1
    11. Tmp = Hex(Hash(i))
    12. If Len(Tmp) = 1 Then Tmp = "0" & Tmp
    13. Result += Tmp
    14. Next
    15. Return Result
    16. End Function
    17. Dim splitted As String() = filelist.Split(CChar(vbNewLine))
    18. Dim splitcount As Integer = splitted.Count
    19. Dim counter As Integer = "0"
    20. Dim lolo As String
    21. For i = 0 To splitcount
    22. Try
    23. If filehash = "" Then
    24. filehash = MD5FileHash(splitted(counter)).ToLower
    25. Else
    26. filehash = filehash + vbNewLine + MD5FileHash(splitted(counter)).ToLower
    27. End If
    28. If newfilelist = "" Then
    29. newfilelist = splitted(counter)
    30. Else
    31. newfilelist = newfilelist + vbNewLine + splitted(counter)
    32. End If
    33. counter = Val(counter) + Val("1")
    34. lolo = counter
    35. Catch ex As Exception
    36. TextBox1.Text &= vbNewLine + ex.Message
    37. End Try
    38. Next i
    39. Try
    40. MkDir("Hashes")
    41. Catch ex As Exception
    42. End Try
    43. Using fw As New System.IO.StreamWriter("Hashes\hashs.txt")
    44. fw.WriteLine(filehash)
    45. End Using
    46. Using fw As New System.IO.StreamWriter("Hashes\filelist.txt")
    47. fw.WriteLine(newfilelist)
    48. End Using
    49. MsgBox("finish")

    plz help me
    Wer Rechtschreibfehler findet darf sie behalten :)
    liegt wahrscheinlich daran das nen illegales Zeichen im Pfad ist? xD
    achte darauf das die Pfads nicht mit Datei namen fütterst indem diese Zeichen vor kommen : \/:*?"<>|

    PS: würde mal tippen das da iwas beim splitten schief gegangen ist
    und seid wann ist integer ein string O.o?

    VB.NET-Quellcode

    1. Dim counter As Integer = "0"
    Wieso steht md5 im titel?
    Glaubst du ernsthaft, dass das was mit md5 zu tun hat?

    Ich wills mal so ausdrücken. Wer lesen kann weiß wo er den Fehler suchen muss. Illegales Zeichen im Pfad!
    Übersetzung: In deinem Dateipfad ist ein Zeichen, welches nicht zugelassen ist.

    Also was macht man da:
    Wenn die Exception fliegt stoppt der Debugger wo die Exception geflogen ist. Also gehst du hin und geht mit der maus über die variable wo der Pfad drinnen ist. Und schaust nach was drinnen steht.
    Wenn du dann nicht drauf kommst kannst du hier nochmal antworten. Willst du wissen wie es zu dem Fehler kommt: Einfach einen Breakpoint (roter punkt ganz links durch click auf den linken rand des editors) setzen. Dann stoppt der Debugger dort und du kannst oben in Schritten weitergehen.

    Ach ja, da dies ein Anfänger Forum ist werd ich dich ganz freundlich drauf hinweisen, dass zu einem guten Programmierstil welcher auch weniger Fehleranfällig ist, dazu gehört, dass man Option Strict On verwendet.

    Und bitte nimm die ganzen Try Catch dinger raus. Die beheben keine Fehler sondern machen es nur schwerer diese zu beheben.


    Opensource Audio-Bibliothek auf github: KLICK, im Showroom oder auf NuGet.
    nene
    also das erste funkt einwandfrei, nur die danach funken nicht :(
    beispielliste:
    Spoiler anzeigen

    Quellcode

    1. C:\Program Files (x86)\7-Zip\7z.exe
    2. C:\Program Files (x86)\7-Zip\7zFM.exe
    3. C:\Program Files (x86)\7-Zip\7zG.exe
    4. C:\Program Files (x86)\7-Zip\Uninstall.exe
    5. C:\Program Files (x86)\7-Zip\7-zip.chm
    6. C:\Program Files (x86)\7-Zip\7-zip.dll
    7. C:\Program Files (x86)\7-Zip\7z.dll
    8. C:\Program Files (x86)\7-Zip\7z.exe
    9. C:\Program Files (x86)\7-Zip\7z.sfx
    10. C:\Program Files (x86)\7-Zip\7zCon.sfx
    11. C:\Program Files (x86)\7-Zip\7zFM.exe
    12. C:\Program Files (x86)\7-Zip\7zG.exe
    13. C:\Program Files (x86)\7-Zip\descript.ion
    14. C:\Program Files (x86)\7-Zip\History.txt
    15. C:\Program Files (x86)\7-Zip\Lang
    16. C:\Program Files (x86)\7-Zip\License.txt
    17. C:\Program Files (x86)\7-Zip\readme.txt
    18. C:\Program Files (x86)\7-Zip\Uninstall.exe
    19. C:\Program Files (x86)\7-Zip\Lang\af.txt
    20. C:\Program Files (x86)\7-Zip\Lang\ar.txt
    21. C:\Program Files (x86)\7-Zip\Lang\ast.txt
    22. C:\Program Files (x86)\7-Zip\Lang\az.txt
    23. C:\Program Files (x86)\7-Zip\Lang\ba.txt
    24. C:\Program Files (x86)\7-Zip\Lang\be.txt
    25. C:\Program Files (x86)\7-Zip\Lang\bg.txt
    26. C:\Program Files (x86)\7-Zip\Lang\bn.txt
    27. C:\Program Files (x86)\7-Zip\Lang\br.txt
    28. C:\Program Files (x86)\7-Zip\Lang\ca.txt
    29. C:\Program Files (x86)\7-Zip\Lang\cs.txt
    30. C:\Program Files (x86)\7-Zip\Lang\cy.txt
    31. C:\Program Files (x86)\7-Zip\Lang\da.txt
    32. C:\Program Files (x86)\7-Zip\Lang\de.txt
    33. C:\Program Files (x86)\7-Zip\Lang\el.txt
    34. C:\Program Files (x86)\7-Zip\Lang\en.ttt
    35. C:\Program Files (x86)\7-Zip\Lang\eo.txt
    36. C:\Program Files (x86)\7-Zip\Lang\es.txt
    37. C:\Program Files (x86)\7-Zip\Lang\et.txt
    38. C:\Program Files (x86)\7-Zip\Lang\eu.txt
    39. C:\Program Files (x86)\7-Zip\Lang\ext.txt
    40. C:\Program Files (x86)\7-Zip\Lang\fa.txt
    41. C:\Program Files (x86)\7-Zip\Lang\fi.txt
    42. C:\Program Files (x86)\7-Zip\Lang\fr.txt
    43. C:\Program Files (x86)\7-Zip\Lang\fur.txt
    44. C:\Program Files (x86)\7-Zip\Lang\fy.txt
    45. C:\Program Files (x86)\7-Zip\Lang\gl.txt
    46. C:\Program Files (x86)\7-Zip\Lang\gu.txt
    47. C:\Program Files (x86)\7-Zip\Lang\he.txt
    48. C:\Program Files (x86)\7-Zip\Lang\hi.txt
    49. C:\Program Files (x86)\7-Zip\Lang\hr.txt
    50. C:\Program Files (x86)\7-Zip\Lang\hu.txt
    51. C:\Program Files (x86)\7-Zip\Lang\hy.txt
    52. C:\Program Files (x86)\7-Zip\Lang\id.txt
    53. C:\Program Files (x86)\7-Zip\Lang\io.txt
    54. C:\Program Files (x86)\7-Zip\Lang\is.txt
    55. C:\Program Files (x86)\7-Zip\Lang\it.txt
    56. C:\Program Files (x86)\7-Zip\Lang\ja.txt
    57. C:\Program Files (x86)\7-Zip\Lang\ka.txt
    58. C:\Program Files (x86)\7-Zip\Lang\kk.txt
    59. C:\Program Files (x86)\7-Zip\Lang\ko.txt
    60. C:\Program Files (x86)\7-Zip\Lang\ku-ckb.txt
    61. C:\Program Files (x86)\7-Zip\Lang\ku.txt
    62. C:\Program Files (x86)\7-Zip\Lang\lt.txt
    63. C:\Program Files (x86)\7-Zip\Lang\lv.txt
    64. C:\Program Files (x86)\7-Zip\Lang\mk.txt
    65. C:\Program Files (x86)\7-Zip\Lang\mn.txt
    66. C:\Program Files (x86)\7-Zip\Lang\mr.txt
    67. C:\Program Files (x86)\7-Zip\Lang\ms.txt
    68. C:\Program Files (x86)\7-Zip\Lang\nb.txt
    69. C:\Program Files (x86)\7-Zip\Lang\ne.txt
    70. C:\Program Files (x86)\7-Zip\Lang\nl.txt
    71. C:\Program Files (x86)\7-Zip\Lang\nn.txt
    72. C:\Program Files (x86)\7-Zip\Lang\pa-in.txt
    73. C:\Program Files (x86)\7-Zip\Lang\pl.txt
    74. C:\Program Files (x86)\7-Zip\Lang\ps.txt
    75. C:\Program Files (x86)\7-Zip\Lang\pt-br.txt
    76. C:\Program Files (x86)\7-Zip\Lang\pt.txt
    77. C:\Program Files (x86)\7-Zip\Lang\ro.txt
    78. C:\Program Files (x86)\7-Zip\Lang\ru.txt
    79. C:\Program Files (x86)\7-Zip\Lang\sa.txt
    80. C:\Program Files (x86)\7-Zip\Lang\si.txt
    81. C:\Program Files (x86)\7-Zip\Lang\sk.txt
    82. C:\Program Files (x86)\7-Zip\Lang\sl.txt
    83. C:\Program Files (x86)\7-Zip\Lang\sq.txt
    84. C:\Program Files (x86)\7-Zip\Lang\sr-spc.txt
    85. C:\Program Files (x86)\7-Zip\Lang\sr-spl.txt
    86. C:\Program Files (x86)\7-Zip\Lang\sv.txt
    87. C:\Program Files (x86)\7-Zip\Lang\ta.txt
    88. C:\Program Files (x86)\7-Zip\Lang\th.txt
    89. C:\Program Files (x86)\7-Zip\Lang\tr.txt
    90. C:\Program Files (x86)\7-Zip\Lang\tt.txt
    91. C:\Program Files (x86)\7-Zip\Lang\ug.txt
    92. C:\Program Files (x86)\7-Zip\Lang\uk.txt
    93. C:\Program Files (x86)\7-Zip\Lang\uz.txt
    94. C:\Program Files (x86)\7-Zip\Lang\va.txt
    95. C:\Program Files (x86)\7-Zip\Lang\vi.txt
    96. C:\Program Files (x86)\7-Zip\Lang\zh-cn.txt
    97. C:\Program Files (x86)\7-Zip\Lang\zh-tw.txt


    und der fehler tritt in der funktion auf.....
    Wer Rechtschreibfehler findet darf sie behalten :)
    Wie gesagt WAS ist im Pfad?
    Du kannst noch länger sagen du hast nen richtigen Pfad. Aber solange du nen "Illegales Zeichen im Pfad" hast wird dir das niemand glauben.

    Somit ist die Diskussion erledigt. Du weißt jetzt wo der Fehler ist. Schau an was es liegen kann. Was ich empfehlen würde wäre nen Trim() für den Pfad (manchmal sind noch tabulatoren oder lehrzeichen kp ob die zugelassen werden also tabs)


    Opensource Audio-Bibliothek auf github: KLICK, im Showroom oder auf NuGet.
    Oh doch ich denke sehr wohl, dass ich sowas verstehe und dabei gibts auch gar nicht viel zu verstehen.
    Dann liest du die liste falsch. Ich sags dir nun zum 3. und letzen mal. Setzt nen Breakpoint und schau was am Dateipfad anders ist als sein sollte.

    Wie gesagt wenn dort steht Illegales Zeichen dann ist da auch nen Illegales Zeichen. So einfach ist das. Einfach die Fehlermeldung lesen und ansonsten mal nen Rat annehmen und machen was man sagt.
    Irgendwas stimmt mit dem Pfad nicht. Wenn du das aus der Liste ausliest, liest du das halt falsch aus.

    Ach ja dinge wie Mkdir kannste gleich weghauen und nie nie nie wieder anschauen. Dafür gibts nun den System.IO namespace.

    Was das auslesen angeht. Vll. solltest du nicht mit Split arbeiten.
    Nimm doch einfach nen StreamReader.
    msdn.microsoft.com/en-us/libra…reader.readline.aspx#Y500


    Opensource Audio-Bibliothek auf github: KLICK, im Showroom oder auf NuGet.