home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / code / various / sizing / inifile.bas < prev    next >
Encoding:
BASIC Source File  |  1995-02-27  |  2.2 KB  |  79 lines

  1. Option Explicit
  2.  
  3. Dim strDir As String
  4. Dim intDirNameLength As Integer
  5.  
  6. Declare Function KRN_GetWindowsDirectory Lib "Kernel" Alias "GetWindowsDirectory" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
  7. Declare Function KRN_GetSystemDirectory Lib "Kernel" Alias "GetSystemDirectory" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
  8.  
  9. Function CopyFile (strFileName As String, strDestination As String) As Integer
  10. '
  11. '   This routine will copy a file to a given destination.
  12. '
  13.     CopyFile = False
  14.  
  15.     On Error GoTo CopyFile_ER
  16.  
  17.     FileCopy strFileName, strDestination
  18.     Exit Function
  19.  
  20. CopyFile_ER:
  21.     CopyFile = Err
  22.     strMsg = "Error in CopyFile, Error is " & Error
  23.     strMsgTitle = "Copy File"
  24.     Exit Function
  25. End Function
  26.  
  27. Function FileExists (strFilePath As String) As Integer
  28. '
  29. '   This routine will check for the existence of a
  30. '   file by attempting an OPEN. It will return a TRUE
  31. '   value if the file exists, FALSE otherwise.
  32. '
  33.     Dim nFile As Integer
  34.  
  35.     nFile = FreeFile
  36.  
  37.     On Error Resume Next
  38.     Open strFilePath For Input As nFile
  39.     If Err = 0 Then
  40.         FileExists = True
  41.     Else
  42.         FileExists = False
  43.     End If
  44.     Close nFile
  45. End Function
  46.  
  47. Function GetWinDir () As String
  48. '
  49. '   This routine will find and return the users windows
  50. '   directory.
  51. '
  52.     strDir = String$(145, 0)              ' Size Buffer
  53.     intDirNameLength = KRN_GetWindowsDirectory(strDir, 145)  ' Make API Call
  54.     strDir = Left$(strDir, intDirNameLength)              ' Trim Buffer
  55.  
  56.     If Right$(strDir, 1) <> "\" Then      ' Add \ if necessary
  57.         GetWinDir = strDir + "\"
  58.     Else
  59.         GetWinDir = strDir
  60.     End If
  61. End Function
  62.  
  63. Function GetWinSysDir () As String
  64. '
  65. '   This routine will return the users windows system
  66. '   directory
  67. '
  68.     strDir = String$(145, 0)                 ' Size Buffer
  69.     intDirNameLength = KRN_GetSystemDirectory(strDir, 145)      ' Make API Call
  70.     strDir = Left$(strDir, intDirNameLength)                 ' Trim Buffer
  71.  
  72.     If Right$(strDir, 1) <> "\" Then         ' Add \ if necessary
  73.         GetWinSysDir = strDir + "\"
  74.     Else
  75.         GetWinSysDir = strDir
  76.     End If
  77. End Function
  78.  
  79.