|
-
Feb 8th, 2021, 09:02 PM
#1
Thread Starter
Banned
threading/backgroundworker
This code to scan drives for particular file types is not working. I'm not getting any errors, but also no results.
Code:
Private Sub ScanDrivesForModsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ScanDrivesForModsToolStripMenuItem.Click
'Dim MyThread As New Threading.Thread(AddressOf Search)
'MyThread.Start()
If Not BW1.IsBusy Then
BW1.RunWorkerAsync()
End If
'Search()
End Sub
Private Sub BW1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BW1.DoWork
Search()
End Sub
Private Sub Search()
For Each drive As System.IO.DriveInfo In My.Computer.FileSystem.Drives
If drive.IsReady = True And drive.DriveType = DriveType.Fixed = True Then
' search for files in the root of the drive
SearchRoot(drive.Name)
For Each SubDir As String In My.Computer.FileSystem.GetDirectories(drive.Name)
' search for files in the folders
SearchDirectories(SubDir)
Next
End If
Next
Dim User As String = SystemInformation.UserName
Dim Di As New DirectoryInfo("C:\Users\" & User)
For Each SubDir As String In My.Computer.FileSystem.GetDirectories(Di.FullName)
SearchDirectories(SubDir)
Next
Label1.Text = Nothing
MsgBox("Scan complete. " & A & " files found.")
End Sub
Private Sub SearchRoot(ByVal RootDir As String)
For Each FileName As String In My.Computer.FileSystem.GetFiles(RootDir, FileIO.SearchOption.SearchTopLevelOnly)
Label1.Text = FileName
ProcessFile(FileName)
Application.DoEvents()
Next
End Sub
Private Sub SearchDirectories(ByVal SubDir As String)
Try
For Each FileName As String In My.Computer.FileSystem.GetFiles(SubDir, FileIO.SearchOption.SearchAllSubDirectories)
Label1.Text = FileName
ProcessFile(FileName)
Application.DoEvents()
Next
Catch ex As Exception
' Typically an error here is access denied issued by some system folders
' This catch will list the folder that wasn't saerched and why with your file list
'MsgBox(ex.Message)
End Try
End Sub
Private Sub ProcessFile(ByVal FileName As String)
Dim Sims3Enabled As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Electronic Arts\The Sims 3\Mods\Packages"
Dim Sims3Disabled As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Electronic Arts\The Sims 3\Mods\Disabled"
Dim Sims4Enabled As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Electronic Arts\The Sims 4\Mods\Packages"
Dim Sims4Disabled As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Electronic Arts\The Sims 4\Mods\Disabled"
Dim Fi As New FileInfo(FileName)
If Fi.DirectoryName <> Sims3Enabled AndAlso Fi.DirectoryName <> Sims3Disabled AndAlso Fi.DirectoryName <> Sims4Enabled AndAlso
Fi.DirectoryName <> Sims4Disabled Then
If Fi.Extension.ToLower = ".package" Then
File.Move(FileName, EnabledDIR.ToString & "\" & Fi.Name)
A += 1
LoadLists()
ElseIf Fi.Extension.ToLower = ".ts4script" Then
Dim FourEnabled As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Electronic Arts\The Sims 4\Mods\Packages"
File.Move(FileName, FourEnabled & "\" & Fi.Name)
A += 1
LoadLists()
ElseIf Fi.Extension.ToLower = ".zip" Then
Try
Zippy = Fi.FullName
Using zip1 As ZipFile = ZipFile.Read(Zippy)
Dim e As ZipEntry
' here, we extract every entry, but we could extract conditionally,
' based on entry name, size, date, checkbox status, etc.
For Each e In zip1
If e.FileName.EndsWith(".package") Then
e.Extract(EnabledDIR, ExtractExistingFileAction.OverwriteSilently)
A += 1
LoadLists()
ElseIf e.FileName.EndsWith(".ts4script") Then
Dim FourEnabled As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Electronic Arts\The Sims 4\Mods\Packages"
e.Extract(FourEnabled, ExtractExistingFileAction.OverwriteSilently)
A += 1
LoadLists()
End If
Next
End Using
Catch ex As Exception
'MsgBox(ex.Message)
End Try
ElseIf Fi.Extension.ToLower = "sims3pack" Then
A += 1
Process.Start(Fi.FullName)
End If
End If
End Sub
-
Feb 8th, 2021, 09:30 PM
#2
Re: threading/backgroundworker
So debug it then. Set a breakpoint, step through the code and compare what you expect to happen with what actually happens. Where the two don't match, you have found an issue. If you can't work out how to fix it, provide us WITH all the RELEVANT information, which means not dumping all your code but only the part required to demonstrate the issue (create a test project that isolates that part if you need to) and an explanation of what it is supposed to do, what it actually does and what data is in use at the time. You're not a user. You're a developer. You have developer tools at your disposal. Use them. Looking at final results and reading code is just the first step in fixing bugs. Asking someone else to fix it is not the second step. We can help but you've got to do your part first.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|