home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / ftpser1a / fndfile.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-08-20  |  4.1 KB  |  130 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "FndFile"
  4.    ClientHeight    =   3195
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   4680
  8.    LinkTopic       =   "FndFile"
  9.    ScaleHeight     =   3195
  10.    ScaleWidth      =   4680
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.TextBox Text3 
  13.       Height          =   1815
  14.       Left            =   240
  15.       MultiLine       =   -1  'True
  16.       ScrollBars      =   2  'Vertical
  17.       TabIndex        =   5
  18.       Text            =   "FndFile.frx":0000
  19.       Top             =   840
  20.       Width           =   4215
  21.    End
  22.    Begin VB.TextBox Text2 
  23.       Height          =   285
  24.       Left            =   960
  25.       TabIndex        =   2
  26.       Text            =   "D:\"
  27.       Top             =   480
  28.       Width           =   2655
  29.    End
  30.    Begin VB.TextBox Text1 
  31.       Height          =   285
  32.       Left            =   960
  33.       TabIndex        =   1
  34.       Text            =   "*.*"
  35.       Top             =   120
  36.       Width           =   1575
  37.    End
  38.    Begin VB.CommandButton Command1 
  39.       Caption         =   "Command1"
  40.       Height          =   375
  41.       Left            =   1320
  42.       TabIndex        =   0
  43.       Top             =   2760
  44.       Width           =   1575
  45.    End
  46.    Begin VB.Label Label2 
  47.       Caption         =   "Directory:"
  48.       Height          =   255
  49.       Left            =   120
  50.       TabIndex        =   4
  51.       Top             =   480
  52.       Width           =   735
  53.    End
  54.    Begin VB.Label Label1 
  55.       Caption         =   "File:"
  56.       Height          =   255
  57.       Left            =   240
  58.       TabIndex        =   3
  59.       Top             =   120
  60.       Width           =   615
  61.    End
  62. Attribute VB_Name = "Form1"
  63. Attribute VB_GlobalNameSpace = False
  64. Attribute VB_Creatable = False
  65. Attribute VB_PredeclaredId = True
  66. Attribute VB_Exposed = False
  67. Option Explicit
  68. Public Function FindFile(ByVal FileName As String, ByVal Path As String) As String
  69. Dim hFile As Long, ts As String, WFD As WIN32_FIND_DATA
  70. Dim result As Long, sAttempt As String, szPath As String
  71. Dim sPath As String
  72.   szPath = GetRDP(Path) & "*.*" & Chr$(0)
  73.   'Note: Inline function here
  74.   '----Starts----
  75.   Dim szPath2 As String, szFilename As String
  76.   Dim dwBufferLen As Long, szBuffer As String, lpFilePart As String
  77.   'Set variables
  78.   szPath2 = Path & Chr$(0)
  79.   szFilename = FileName & Chr$(0)
  80.   szBuffer = String$(MAX_PATH, 0)
  81.   dwBufferLen = Len(szBuffer)
  82.   'Ask windows if it can find a file matching the filename you gave it.
  83.   result = SearchPath(szPath2, szFilename, vbNullString, dwBufferLen, szBuffer, lpFilePart)
  84.   '----Ends----
  85.   If result Then
  86.     FindFile = StripNull(szBuffer)
  87.     Exit Function
  88.   End If
  89.   'Start asking windows for files.
  90.   hFile = FindFirstFile(szPath, WFD)
  91.     ts = StripNull(WFD.cFileName)
  92.     Debug.Print ts; Len(ts)
  93.     Text3.Text = Text3.Text & ts & vbCrLf
  94.     'If WFD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY Then
  95.     '  'Hey look, we've got a directory!
  96.     '  If Not (ts = "." Or ts = "..") Then
  97.     '    'Don't look for hidden or system directories
  98.     '    If Not (WFD.dwFileAttributes And (FILE_ATTRIBUTE_HIDDEN Or FILE_ATTRIBUTE_SYSTEM)) Then
  99.     '      'Search directory recursively
  100.     '      sAttempt = FindFile(FileName, GetRDP(Path) & ts)
  101.     '      If sAttempt <> "" Then
  102.     '        FindFile = sAttempt
  103.     '        Exit Do
  104.     '      End If
  105.     '    End If
  106.     '  End If
  107.     'End If
  108.     WFD.cFileName = ""
  109.     result = FindNextFile(hFile, WFD)
  110.   Loop Until result = 0
  111.   FindClose hFile
  112. End Function
  113. Public Function StripNull(ByVal WhatStr As String) As String
  114.   If InStr(WhatStr, Chr$(0)) > 0 Then
  115.     StripNull = Left$(WhatStr, InStr(WhatStr, Chr$(0)) - 1)
  116.   Else
  117.     StripNull = WhatStr
  118.   End If
  119. End Function
  120. Public Function GetRDP(ByVal sPath As String) As String
  121. 'Adds a backslash on the end of a path, if required.
  122.   If sPath = "" Then Exit Function
  123.   If Right$(sPath, 1) = "\" Then GetRDP = sPath: Exit Function
  124.     GetRDP = sPath & "\"
  125. End Function
  126. Private Sub Command1_Click()
  127. Dim t3 As String
  128.  t3 FindFile(Text1, Text2)
  129. End Sub
  130.