FileControl.bas
Upload User: wintows
Upload Date: 2009-11-16
Package Size: 27k
Code Size: 17k
Category:

Windows Develop

Development Platform:

Visual Basic

  1. Attribute VB_Name = "FileControl"
  2. 'Download by http://www.codefans.net
  3. Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
  4. Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
  5. Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
  6. Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
  7. Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
  8. Public Declare Function GetLogicalDrives Lib "kernel32" () As Long
  9. Public Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
  10. 'Find Files
  11. Declare Function SearchTreeForFile Lib "IMAGEHLP.DLL" (ByVal lpRootPath As String, ByVal lpInputName As String, ByVal lpOutputName As String) As Long
  12. 'Browse for DIR
  13. 'API's for selecting a windows directory
  14. Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
  15. Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
  16. Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
  17. Private Type BROWSEINFO
  18.    hOwner           As Long
  19.    pidlRoot         As Long
  20.    pszDisplayName   As String
  21.    lpszTitle        As String
  22.    ulFlags          As Long
  23.    lpfn             As Long
  24.    lParam           As Long
  25.    iImage           As Long
  26. End Type
  27. 'Constants
  28. Public OurFiles As String 'Returns list of files found in DIR
  29. Function IfFileExists(ByVal sFilename As String) As Boolean
  30.     Dim I As Long
  31.     On Error Resume Next
  32.     I = Len(Dir$(sFilename))
  33.     If Err Or I = 0 Then
  34.         IfFileExists = False
  35.     Else
  36.         IfFileExists = True
  37.     End If
  38. End Function
  39. Sub SaveTextAppend(Path As String, StringName As String)
  40.     On Error Resume Next
  41.     Open Path$ For Append As #1
  42.     Print #1, StringName
  43.     Close #1
  44. End Sub
  45. Sub SaveTextOutput(Path As String, StringName As String)
  46.     On Error Resume Next
  47.     Open Path$ For Output As #1
  48.     Print #1, StringName
  49.     Close #1
  50. End Sub
  51. Public Function FolderExist(ByVal pName As String) As Boolean
  52.     Rem ---------------------------------
  53.     Rem Check folder
  54.     Rem ---------------------------------
  55.     Dim lFso As Scripting.FileSystemObject
  56.     On Error GoTo Cerr
  57.     Set lFso = New Scripting.FileSystemObject
  58.     FolderExist = lFso.FolderExists(pName)
  59.     Exit Function
  60. Cerr:
  61.     FolderExist = False
  62. End Function
  63. Public Function FileExists2(sFilename As String) As Boolean
  64.     If Len(sFilename$) = 0 Then
  65.         FileExists2 = False
  66.         Exit Function
  67.     End If
  68.     If Len(Dir$(sFilename$)) Then
  69.         FileExists2 = True
  70.     Else
  71.         FileExists2 = False
  72.     End If
  73. End Function
  74. Public Function FileExists(ByVal pFilename As String) As Boolean
  75.     Rem ---------------------------------
  76.     Rem Check for file existence
  77.     Rem ---------------------------------
  78.     On Error GoTo FileExists_Err
  79.     If FileLen(pFilename) > 0 Then
  80.         FileExists = True
  81.     Else
  82.         FileExists = False
  83.     End If
  84.     GoTo FileExists_Out
  85. FileExists_Err:
  86.     FileExists = False
  87. FileExists_Out:
  88. End Function
  89. Public Function DirExists(strDir As String) As Boolean
  90.     'change C:MyDir
  91.     strDir = Dir(strDir, vbDirectory)
  92.     If (strDir = "") Then
  93.         DirExists = False
  94.     Else
  95.         DirExists = True
  96.     End If
  97. End Function
  98. Public Sub SaveListBox(Directory As String, TheList As ListBox)
  99.     Dim savelist As Long
  100.     On Error Resume Next
  101.     fe = FreeFile
  102.     Open Directory$ For Output As #fe
  103.     For savelist = 0 To TheList.ListCount - 1
  104.     bufff = TheList.List(savelist)
  105.     bufff = Replace(bufff, Chr(13), "