home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / VISUAL_B / CODIGO_1 / FINDFILE / FINDFILE.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-05-20  |  6.3 KB  |  216 lines

  1. VERSION 2.00
  2. Begin Form FindFile 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Find File"
  5.    ClientHeight    =   2520
  6.    ClientLeft      =   1095
  7.    ClientTop       =   1590
  8.    ClientWidth     =   7365
  9.    Height          =   2925
  10.    Icon            =   FINDFILE.FRX:0000
  11.    Left            =   1035
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   2520
  14.    ScaleWidth      =   7365
  15.    Top             =   1245
  16.    Width           =   7485
  17.    Begin CommandButton CancelBtn 
  18.       Caption         =   "Cancel"
  19.       Height          =   510
  20.       Left            =   5850
  21.       TabIndex        =   5
  22.       Top             =   1710
  23.       Visible         =   0   'False
  24.       Width           =   1230
  25.    End
  26.    Begin CommandButton OKBtn 
  27.       Caption         =   "OK"
  28.       Height          =   510
  29.       Left            =   5850
  30.       TabIndex        =   4
  31.       Top             =   1125
  32.       Width           =   1230
  33.    End
  34.    Begin TextBox Containing 
  35.       Height          =   285
  36.       Left            =   4095
  37.       TabIndex        =   1
  38.       Top             =   675
  39.       Width           =   2985
  40.    End
  41.    Begin SSCheck IncludeSub 
  42.       Alignment       =   1  'Right Justify
  43.       Caption         =   "Include Subdirectories"
  44.       Height          =   285
  45.       Left            =   2925
  46.       TabIndex        =   2
  47.       Top             =   1260
  48.       Value           =   -1  'True
  49.       Width           =   2220
  50.    End
  51.    Begin TextBox FileSpec 
  52.       Height          =   285
  53.       Left            =   4635
  54.       MaxLength       =   12
  55.       TabIndex        =   0
  56.       Text            =   "*.*"
  57.       Top             =   180
  58.       Width           =   2445
  59.    End
  60.    Begin DirListBox Dir1 
  61.       Height          =   2055
  62.       Left            =   315
  63.       TabIndex        =   6
  64.       Top             =   135
  65.       Width           =   2310
  66.    End
  67.    Begin DriveListBox Drive1 
  68.       Height          =   315
  69.       Left            =   3015
  70.       TabIndex        =   3
  71.       Top             =   1845
  72.       Width           =   2355
  73.    End
  74.    Begin Label Label1 
  75.       BackStyle       =   0  'Transparent
  76.       Caption         =   "Containing:"
  77.       Height          =   240
  78.       Index           =   1
  79.       Left            =   2970
  80.       TabIndex        =   8
  81.       Top             =   720
  82.       Width           =   1095
  83.    End
  84.    Begin Label Label1 
  85.       BackStyle       =   0  'Transparent
  86.       Caption         =   "File Specification:"
  87.       Height          =   240
  88.       Index           =   0
  89.       Left            =   2970
  90.       TabIndex        =   7
  91.       Top             =   225
  92.       Width           =   1770
  93.    End
  94. Option Explicit
  95. Option Compare Text
  96. Dim F1 As Found
  97. Dim CancelFlag As Integer
  98. Sub CancelBtn_Click ()
  99. CancelFlag = True
  100. End Sub
  101. Sub Drive1_Change ()
  102. Dir1.Path = Left$(Drive1.Drive, 2)
  103. End Sub
  104. Function FileContains (FileName As String, SearchText As String) As Integer
  105. Dim FileNumber As Integer
  106. Dim FileLength As Long
  107. Dim Chunk As String
  108. Dim ChunkStart As Long
  109. Const MaxChunk = 20000
  110. On Error GoTo FileContainsError
  111. FileNumber = FreeFile
  112. Open FileName For Binary Access Read Shared As FileNumber
  113. FileLength = LOF(FileNumber)
  114. ChunkStart = 0
  115. Do Until ChunkStart = FileLength
  116.     If FileLength - ChunkStart > MaxChunk Then
  117.         Chunk = Input$(MaxChunk, FileNumber)
  118.         ChunkStart = ChunkStart + MaxChunk - Len(SearchText)
  119.     Else
  120.         Chunk = Input$(FileLength - ChunkStart, FileNumber)
  121.         ChunkStart = FileLength
  122.     End If
  123.     If InStr(Chunk, SearchText) > 0 Then
  124.         FileContains = True
  125.         Exit Do
  126.     End If
  127. Close FileNumber
  128. Exit Function
  129. FileContainsError:
  130.     Select Case Err
  131.         Case Else
  132.             MsgBox Error$ & " on file " & FileName
  133.     End Select
  134.     Exit Function
  135. End Function
  136. Sub Find (SearchPath As String)
  137. ReDim DirName(0 To 15) As String
  138. Dim DirCount As Integer
  139. Dim FileName As String, Attributes As Integer
  140. Dim x As Integer
  141. If Right$(SearchPath, 1) <> "\" Then SearchPath = SearchPath & "\"
  142. DirCount = 0
  143. FileName = Dir$(SearchPath & FileSpec, Attr_Normal + Attr_System + Attr_Hidden)
  144. Do Until FileName = ""
  145.     If Containing = "" Then
  146.         F1.FoundFiles.AddItem SearchPath & FileName
  147.     Else
  148.         If FileContains(SearchPath & FileName, (Containing.Text)) Then
  149.             F1.FoundFiles.AddItem SearchPath & FileName
  150.         End If
  151.     End If
  152.     FileName = Dir$
  153.     DoEvents
  154.     If CancelFlag Then Exit Sub
  155. If IncludeSub Then
  156.     FileName = Dir$(SearchPath & "*.*", Attr_Normal + Attr_System + Attr_Hidden + Attr_Directory)
  157.     Do Until FileName = ""
  158.         If FileName <> "." And FileName <> ".." Then
  159.             Attributes = GetAttr(SearchPath & FileName)
  160.             If (Attributes And Attr_Directory) Then
  161.                 If DirCount > UBound(DirName) Then
  162.                     ReDim Preserve DirName(0 To DirCount + 15)
  163.                 End If
  164.                 DirName(DirCount) = SearchPath & FileName
  165.                 DirCount = DirCount + 1
  166.             End If
  167.         End If
  168.         FileName = Dir$
  169.         DoEvents
  170.         If CancelFlag Then Exit Sub
  171.     Loop
  172.     For x = 0 To DirCount - 1
  173.         Find DirName(x)
  174.     Next x
  175. End If
  176. End Sub
  177. Sub Form_Unload (Cancel As Integer)
  178. If Forms.Count > 1 Then
  179.     Select Case MsgBox("Close search windows also?", MB_YesNoCancel)
  180.         Case IDYes
  181.             End
  182.         Case IDCancel
  183.             Cancel = True
  184.     End Select
  185. End If
  186.             
  187. End Sub
  188. Sub OKBtn_Click ()
  189. 'MousePointer = Hourglass
  190. OKBtn.Enabled = False
  191. Caption = "Find File - Searching"
  192. CancelBtn.Visible = True
  193. Set F1 = New Found
  194. CancelFlag = False
  195. If FileSpec = "" Then FileSpec = "*.*"
  196. Find (Dir1.Path)
  197. Caption = "Find File"
  198. CancelBtn.Visible = False
  199. If CancelFlag Then
  200.     Unload F1
  201.     Select Case F1.FoundFiles.ListCount
  202.         Case 0
  203.             MsgBox "No files matching the search criteria were found."
  204.             Unload F1
  205.         Case 1
  206.             F1.Caption = F1.FoundFiles.ListCount & " File Found"
  207.             F1.Show
  208.         Case Else
  209.             F1.Caption = F1.FoundFiles.ListCount & " Files Found"
  210.             F1.Show
  211.     End Select
  212. End If
  213. OKBtn.Enabled = True
  214. 'MousePointer = Default
  215. End Sub
  216.