Anulowany

10323 Poprawienie modułu - Visual Basic 6

Poniżej kod. Problem jest taki, że gdy używam komendy, np:

[url removed, login to view] \"*.*\", \"C:\\\" to kod powinien przeszukać cały dysk twardy, a nie tylko katalog C. Rozumiem przez to, że C jest najwyższym katalogiem, a wszelkie subdirs i sub-sub dirs powinny zostać przeszukane (wszystkie pliki).

Kontakt: tomrell@[url removed, login to view]

Kod modułu:

Option Explicit

Public Searching As Boolean

Private ObjectsScanned As Double

Private ObjectsMalicious As Double

Public Function ScanName(FullFilename As String) As String

Dim Filenameonly As String

On Error Resume Next

Filenameonly = Mid(FullFilename, InStrRev(FullFilename, \"\\\") + 1)

[url removed, login to view] = [url removed, login to view] & \"\\[url removed, login to view]\"

[url removed, login to view] = \"Scanfiles\"

[url removed, login to view] = UCase(Filenameonly)

ScanName = [url removed, login to view]

If ScanName <> \"\" Then

Log Filenameonly & \", a running process, is found as malicious. Suspsending: \" & ScanName

End If

End Function

Public Function GetFilenameonly(FullFilename As String) As String

On Error Resume Next

GetFilenameonly = Mid(FullFilename, InStrRev(FullFilename, \"\\\") + 1)

End Function

Private Sub StartSearch(FileToSearch As String, SearchDirectory As String)

Dim CurrentCharacter As Integer \' A pointer of a character in a String

Dim item As ListItem \'Add item to scan listview

Dim CurrentDirectory As Integer \' The Index of the CurrentDirectory

Dim Directories() As String \' Holds the name of the directory

ReDim Directories(0)

Dim DirectoryCount As Integer \' Number of dierctory in a directory

Dim DirectoryName As String \' Holds the name of the directory

Dim Filename As String \' Holds the name of the file

Dim ListViewItemX As ListItem

Dim ListViewItemCount As Integer

Dim strGetINI \'Holds the string value for INI file

\' Stop the search if Searching suddenly turn to False

If Searching = False Then Exit Sub

On Error Resume Next \' Error Handling

If [url removed, login to view] = False Then Exit Sub

\' If the user didn\'t enter anythingn in SearchDirectory, assume it is \"C:\\\"

If Len(SearchDirectory) <= 0 Then SearchDirectory = \"C:\\\"

\' Make sure the last character of SearchDirectory is not \"\\\"

CurrentCharacter = Len(SearchDirectory)

Do Until Mid(SearchDirectory, CurrentCharacter, 1) <> \"\\\"

\' Remove last character

SearchDirectory = Left(SearchDirectory, CurrentCharacter - 1)

\' Continue to go backward

CurrentCharacter = CurrentCharacter - 1

Loop

\' If the user didn\'t enter the extension of the file, place while card

\' character at the end of the String

CurrentCharacter = Len(FileToSearch)

\' Go into the loop ONLY when user enter something

If Len(FileToSearch) > 0 Then

Do Until Mid(FileToSearch, CurrentCharacter, 1) = \".\" Or _

CurrentCharacter <= 1

CurrentCharacter = CurrentCharacter - 1

Loop

End If

\' Check teh value Current Charcater. If it is 1, that\'s mean the user

\' didn\'t enter any extension

If CurrentCharacter <= 1 Then

\' Insert wild card character at the end of the string

FileToSearch = FileToSearch & \"*\"

End If

\' Find all directories first

\' Retrieve the first entry.

DirectoryName = Dir(SearchDirectory & \"\\\", vbDirectory)

\' Start the loop

Do While DirectoryName <> \"\"

\' Ignore the current directory and the encompassing directory.

If DirectoryName <> \".\" And DirectoryName <> \"..\" Then

\' Use bitwise comparison to make sure Directory is a directory.

Select Case GetAttr(SearchDirectory & \"\\\" & DirectoryName)

Case vbDirectory To vbDirectory + vbSystem

\' Save Directory

ReDim Preserve Directories(DirectoryCount + 1)

Directories(DirectoryCount) = DirectoryName

DirectoryCount = DirectoryCount + 1

End Select

End If

\' Get next entry

DirectoryName = Dir

Loop

\' Find file(s)

\' Retrieve the first entry.

DirectoryName = Dir(SearchDirectory & \"\\\", vbDirectory)

\' Start the loop

Do While DirectoryName <> \"\"

\' Ignore the current directory and the encompassing directory.

If DirectoryName <> \".\" And DirectoryName <> \"..\" Then

\' Use bitwise comparison to make sure Directory is a directory.

Select Case GetAttr(SearchDirectory & \"\\\" & DirectoryName)

Case vbDirectory To vbDirectory + vbSystem

\' Search all contents in this direcotry

StartSearch FileToSearch, SearchDirectory & \"\\\" & DirectoryName

End Select

End If

\' Get next entry

DirectoryName = Dir(SearchDirectory & \"\\\", vbDirectory)

Do

\' Loop until we find the next directory name

DirectoryName = Dir

Loop Until DirectoryName = Directories(CurrentDirectory) Or _

Directories(CurrentDirectory) = \"\" Or _

DirectoryName = \"\"

If Directories(CurrentDirectory) = \"\" Then Exit Do

\' Change pointer

CurrentDirectory = CurrentDirectory + 1

DoEvents

\' Stop the search if Searching suddenly turn to False

If Searching = False Then Exit Sub

Loop

\' Find file now

\' Retrieve the first entry

Filename = Dir(SearchDirectory & \"\\\" & FileToSearch, vbDirectory)

\' Start the loop

Do While Filename <> \"\"

\' Ingore the current directory and the encompassing directory.

If Filename <> \".\" And Filename <> \"..\" Then

\'\'\'\' SCAN FILES HERE \'\'\'\'

[url removed, login to view] = SearchDirectory & \"\\\" & Filename

strGetINI = \"\"

[url removed, login to view] = UCase(Filename)

strGetINI = UCase([url removed, login to view])

ObjectsScanned = ObjectsScanned + 1

[url removed, login to view] = ObjectsScanned

\'doevents to refrsh

DoEvents

If strGetINI <> \"\" Then

Set item = [url removed, login to view]()

[url removed, login to view] = strGetINI

[url removed, login to view](1) = SearchDirectory & \"\\\" & Filename

[url removed, login to view] = 1

[url removed, login to view] = 1

[url removed, login to view] = True

ObjectsMalicious = ObjectsMalicious + 1

[url removed, login to view] = ObjectsMalicious

Log strGetINI & \" was found in \" & [url removed, login to view](1)

End If

End If

\' Get next entry

Filename = Dir

Loop

End Sub

Public Function FindFile(FileToSearch As String, SearchDirectory As String) As String

\'Set default values

ObjectsScanned = 0

ObjectsMalicious = 0

\' Check current status

If Searching = True Then

\' Reset value

Searching = False

Exit Function

Else

If [url removed, login to view] = True Then

\' Set value to True

Searching = True

Else

Unload frmScan

End If

End If

If [url removed, login to view] = False Then Exit Function

\' Start the search

StartSearch FileToSearch, SearchDirectory

\' Reset value

Searching = False

End Function

Umiejętności: Android, iPad, iPhone, Mobile App Development

Zobacz więcej: use case extension, the string problem, string searching in c, string searching, searching index of, searching a string in c, searching a string, search character in string, find character in string c, basic icon, boolean search string, visual basic 6.0, visual basic app, taki, resume u, redim, poni, modu, len, find files in directory

O pracodawcy:
( 29 ocen ) Białystok, Poland

Numer ID Projektu: #5586511