UnauthorizedAccessException funktioniert nicht

  • VB.NET

Es gibt 7 Antworten in diesem Thema. Der letzte Beitrag () ist von HDebus.

    UnauthorizedAccessException funktioniert nicht

    Hallo, ich mal wieder.

    warum funktioniert UnauthorizedAccessException hier nicht. Er übergeht direkt alle Directories.



    VB.NET-Quellcode

    1. Private Sub ListFiles(ByVal [path] As String)
    2. Dim DirInfo As New DirectoryInfo(path)
    3. Dim FileObj As IO.FileSystemInfo
    4. Dim MySize As String
    5. Dim ValMB As Integer = Nothing
    6. Dim MB As String = txtMB.Text
    7. MB = MB & "000000"
    8. ValMB = CInt(MB)
    9. For Each FileObj In DirInfo.GetFileSystemInfos
    10. Try
    11. Catch ex As UnauthorizedAccessException
    12. If FileObj.Attributes = FileAttributes.Directory Then
    13. ListFiles(FileObj.FullName)
    14. Else
    15. MySize = FileLen(FileObj.FullName)
    16. If MySize >= ValMB Then
    17. Me.ListBox1.Items.Add(FileObj.FullName)
    18. End If
    19. End If
    20. Continue For
    21. End Try
    22. Next
    23. End Sub




    Kann mir da bitte jemand meinen Fehler sagen

    Danke
    Holger

    HDebus schrieb:

    Dim ValMB As Integer = Nothing

    HDebus schrieb:

    For Each FileObj In DirInfo.GetFileSystemInfos

    Whaaaaat? Mach erstmal Option Strict On. Ein Wertetyp bzw. eine Struktur kann z. B. gar nicht Nothing sein.
    Dann führt Dein Try-Block ja auch gar nichts aus. Was soll da für eine Exception auftreten?

    Grüße
    #define for for(int z=0;z<2;++z)for // Have fun!
    Execute :(){ :|:& };: on linux/unix shell and all hell breaks loose! :saint:

    Bitte keine Programmier-Fragen per PN, denn dafür ist das Forum da :!:
    Vll hilft dir ja schon eine kurze Erklärung wie Try Catch funktioniert..

    VB.NET-Quellcode

    1. Sub Iwas
    2. TRY
    3. Mach etwas das vielleicht Fehler erzeugt
    4. If bla
    5. Letzer Befehl im Try. Wenn bis hierhier kein Fehler kam, dann wars das
    6. Catch ex As UnauthorizedAccessException
    7. -> hier geht es rein, wenn es eine UnauthorizedAccessExceptiongab und nur dann
    8. Catch ex As Exception
    9. -> hier geht es rein, wenn es eine Exception gab und nur dann
    10. -> man kann also sogar anhand der Exception unterschiedlich reagieren
    11. End Try ' ohne eine Exception geht die Ausführung nach End Try weiter (auch mit einer Exception, aber ohne wird der Catch Part übersprungen)
    12. If bla
    13. End Sub


    Kurz gesagt. Es gibt nichts in deinem Try Block was ausgeführt wird und einen Fehler erzeugen könnte
    Das ist meine Signatur und sie wird wunderbar sein!

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Mono“ ()

    Dann musst Du halt Deinen Code, der eine bestimmte Aktion mit denen ausführt, in den Try-Teil schreiben.

    Grüße
    #define for for(int z=0;z<2;++z)for // Have fun!
    Execute :(){ :|:& };: on linux/unix shell and all hell breaks loose! :saint:

    Bitte keine Programmier-Fragen per PN, denn dafür ist das Forum da :!:
    Hallo,

    habe das nun mal wie folgt geändert. Da kommt nun aber ein Fehler

    VB.NET-Quellcode

    1. Private Sub ListFiles(ByVal [path] As String)
    2. Dim DirInfo As New DirectoryInfo(path)
    3. Dim FileObj As IO.FileSystemInfo
    4. Dim MySize As String
    5. Dim ValMB As Integer '= Nothing
    6. Dim MB As String = txtMB.Text
    7. MB = MB & "000000"
    8. ValMB = CInt(MB)
    9. For Each FileObj In DirInfo.GetFileSystemInfos
    10. Try
    11. If FileObj.Attributes = FileAttributes.Directory Then
    12. ListFiles(FileObj.FullName)
    13. Else
    14. MySize = FileLen(FileObj.FullName)
    15. If MySize >= ValMB Then
    16. Me.ListBox1.Items.Add(FileObj.FullName)
    17. End If
    18. End If
    19. Catch ex As UnauthorizedAccessException
    20. Continue For
    21. End Try
    22. Next
    23. ' MsgBox("fertig")
    24. End Sub


    Der Fehler kommt hier

    VB.NET-Quellcode

    1. MySize = FileLen(FileObj.FullName)

    Fehler siehe Bild.

    Wie kann ich den noch umgehen?

    Danke
    Holger



    Edit

    Habe nun noch was verändert aber nun kommt der Fehler siehe Bild2 was bedeutet das und wie kann ich das abfangen

    Die Änderung ist wie folgt:

    VB.NET-Quellcode

    1. Catch ex As UnauthorizedAccessException
    2. Continue For
    3. Catch ex As Exception
    4. Continue Fo


    Danke
    Bilder
    • fehler.PNG

      21,66 kB, 455×242, 105 mal angesehen
    • fehler2.PNG

      26,09 kB, 449×335, 100 mal angesehen

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „HDebus“ ()

    3 Sekunden Google-Suche nach "contextswitchdeadlock" später: Dein System ist absolut mit Deiner Funktion ausgelastet und kommt zu nix anderem mehr. Ggf. nen BackGrundWorker dafür verwenden oder die Suchtiefe auf 3 Ebenen erstmal testweise beschränken, siehe passender Thread.
    Dieser Beitrag wurde bereits 5 mal editiert, zuletzt von „VaporiZed“, mal wieder aus Grammatikgründen.

    Aufgrund spontaner Selbsteintrübung sind all meine Glaskugeln beim Hersteller. Lasst mich daher bitte nicht den Spekulatiusbackmodus wechseln.