home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / ch_code / ch13 / fileinfo / fileinfo.frm (.txt) next >
Encoding:
Visual Basic Form  |  1996-04-30  |  8.0 KB  |  220 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Begin VB.Form Form1 
  4.    Caption         =   "File Information"
  5.    ClientHeight    =   2910
  6.    ClientLeft      =   60
  7.    ClientTop       =   330
  8.    ClientWidth     =   6030
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   2910
  11.    ScaleWidth      =   6030
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin MSComDlg.CommonDialog CommonDialog1 
  14.       Left            =   345
  15.       Top             =   2235
  16.       _ExtentX        =   847
  17.       _ExtentY        =   847
  18.       _Version        =   393216
  19.       FontSize        =   1.17491e-38
  20.    End
  21.    Begin VB.Frame Frame1 
  22.       Caption         =   "File Attributes"
  23.       BeginProperty Font 
  24.          Name            =   "Verdana"
  25.          Size            =   9
  26.          Charset         =   0
  27.          Weight          =   400
  28.          Underline       =   0   'False
  29.          Italic          =   0   'False
  30.          Strikethrough   =   0   'False
  31.       EndProperty
  32.       Height          =   1815
  33.       Left            =   120
  34.       TabIndex        =   1
  35.       Top             =   120
  36.       Width           =   5655
  37.       Begin VB.Label Label7 
  38.          BeginProperty Font 
  39.             Name            =   "Verdana"
  40.             Size            =   9
  41.             Charset         =   0
  42.             Weight          =   400
  43.             Underline       =   0   'False
  44.             Italic          =   0   'False
  45.             Strikethrough   =   0   'False
  46.          EndProperty
  47.          Height          =   255
  48.          Left            =   2310
  49.          TabIndex        =   7
  50.          Top             =   1320
  51.          Width           =   2985
  52.       End
  53.       Begin VB.Label Label6 
  54.          BeginProperty Font 
  55.             Name            =   "Verdana"
  56.             Size            =   9
  57.             Charset         =   0
  58.             Weight          =   400
  59.             Underline       =   0   'False
  60.             Italic          =   0   'False
  61.             Strikethrough   =   0   'False
  62.          EndProperty
  63.          Height          =   255
  64.          Left            =   2310
  65.          TabIndex        =   6
  66.          Top             =   840
  67.          Width           =   2985
  68.       End
  69.       Begin VB.Label Label5 
  70.          BeginProperty Font 
  71.             Name            =   "Verdana"
  72.             Size            =   9
  73.             Charset         =   0
  74.             Weight          =   400
  75.             Underline       =   0   'False
  76.             Italic          =   0   'False
  77.             Strikethrough   =   0   'False
  78.          EndProperty
  79.          Height          =   255
  80.          Left            =   2310
  81.          TabIndex        =   5
  82.          Top             =   360
  83.          Width           =   2985
  84.       End
  85.       Begin VB.Label Label3 
  86.          Caption         =   "File Size:"
  87.          BeginProperty Font 
  88.             Name            =   "Verdana"
  89.             Size            =   9
  90.             Charset         =   0
  91.             Weight          =   400
  92.             Underline       =   0   'False
  93.             Italic          =   0   'False
  94.             Strikethrough   =   0   'False
  95.          EndProperty
  96.          Height          =   255
  97.          Left            =   120
  98.          TabIndex        =   4
  99.          Top             =   1320
  100.          Width           =   855
  101.       End
  102.       Begin VB.Label Label2 
  103.          Caption         =   "File Attributes:"
  104.          BeginProperty Font 
  105.             Name            =   "Verdana"
  106.             Size            =   9
  107.             Charset         =   0
  108.             Weight          =   400
  109.             Underline       =   0   'False
  110.             Italic          =   0   'False
  111.             Strikethrough   =   0   'False
  112.          EndProperty
  113.          Height          =   255
  114.          Left            =   120
  115.          TabIndex        =   3
  116.          Top             =   840
  117.          Width           =   1695
  118.       End
  119.       Begin VB.Label Label1 
  120.          Caption         =   "File Name:"
  121.          BeginProperty Font 
  122.             Name            =   "Verdana"
  123.             Size            =   9
  124.             Charset         =   0
  125.             Weight          =   400
  126.             Underline       =   0   'False
  127.             Italic          =   0   'False
  128.             Strikethrough   =   0   'False
  129.          EndProperty
  130.          Height          =   255
  131.          Left            =   120
  132.          TabIndex        =   2
  133.          Top             =   360
  134.          Width           =   975
  135.       End
  136.    End
  137.    Begin VB.CommandButton Command1 
  138.       Caption         =   "Get File Info"
  139.       BeginProperty Font 
  140.          Name            =   "Verdana"
  141.          Size            =   9.75
  142.          Charset         =   0
  143.          Weight          =   400
  144.          Underline       =   0   'False
  145.          Italic          =   0   'False
  146.          Strikethrough   =   0   'False
  147.       EndProperty
  148.       Height          =   495
  149.       Left            =   3345
  150.       TabIndex        =   0
  151.       Top             =   2280
  152.       Width           =   2415
  153.    End
  154. Attribute VB_Name = "Form1"
  155. Attribute VB_GlobalNameSpace = False
  156. Attribute VB_Creatable = False
  157. Attribute VB_PredeclaredId = True
  158. Attribute VB_Exposed = False
  159. '  ******************************
  160. '  ******************************
  161. '  ** MASTERING VB6            **
  162. '  ** by Evangelos Petroutos   **
  163. '  ** SYBEX, 1998              **
  164. '  ******************************
  165. '  ******************************
  166. Option Explicit
  167. Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" _
  168.     (ByVal lpFileName As String) As Long
  169. Private Declare Function GetFullPathName Lib "kernel32" Alias "GetFullPathNameA" _
  170.     (ByVal lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, _
  171.     ByVal lpFilePart As String) As Long
  172. Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
  173.     (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, _
  174.     ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Any, _
  175.     ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, _
  176.     ByVal hTemplateFile As Long) As Long
  177. Private Declare Function GetFileSize Lib "kernel32" _
  178.     (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
  179. Private Declare Function CloseHandle Lib "kernel32" _
  180.     (ByVal hObject As Long) As Long
  181. Const FILE_ATTRIBUTE_ARCHIVE = &H20
  182. Const FILE_ATTRIBUTE_COMPRESSED = &H800
  183. Const FILE_ATTRIBUTE_DIRECTORY = &H10
  184. Const FILE_ATTRIBUTE_HIDDEN = &H2
  185. Const FILE_ATTRIBUTE_NORMAL = &H80
  186. Const FILE_ATTRIBUTE_READONLY = &H1
  187. Const FILE_ATTRIBUTE_SYSTEM = &H4
  188. Const GENERIC_READ = &H80000000
  189. Const OPEN_EXISTING = 3
  190. Const GENERIC_WRITE = &H40000000
  191. Private Sub Command1_Click()
  192. Dim retValue As Long
  193. Dim filePath As String * 255
  194. Dim attrFlag As Long
  195. Dim attrStr As String, fileName As String
  196. Dim filePointer As Long, fileSize As Long
  197.     CommonDialog1.ShowOpen
  198.     If CommonDialog1.fileName <> "" Then fileName = CommonDialog1.fileName
  199.     'Get full path for file name
  200.     retValue = GetFullPathName(fileName, 255, filePath, 0)
  201.     Label5.Caption = filePath
  202.     'Get file attributes
  203.     attrFlag = GetFileAttributes(fileName)
  204.     If (attrFlag And FILE_ATTRIBUTE_ARCHIVE) Then attrStr = "A"
  205.     If (attrFlag And FILE_ATTRIBUTE_COMPRESSED) Then attrStr = attrStr & "C"
  206.     If (attrFlag And FILE_ATTRIBUTE_DIRECTORY) Then attrStr = attrStr & "D"
  207.     If (attrFlag And FILE_ATTRIBUTE_HIDDEN) Then attrStr = attrStr & "H"
  208.     If (attrFlag And FILE_ATTRIBUTE_NORMAL) Then attrStr = attrStr & "N"
  209.     If (attrFlag And FILE_ATTRIBUTE_READONLY) Then attrStr = attrStr & "R"
  210.     If (attrFlag And FILE_ATTRIBUTE_SYSTEM) Then attrStr = attrStr & "S"
  211.     Label6.Caption = attrStr
  212.     'Get file size
  213.     filePointer = CreateFile(fileName, GENERIC_READ Or GENERIC_WRITE, 0&, 0&, OPEN_EXISTING, _
  214.                                 FILE_ATTRIBUTE_NORMAL, 0&)
  215.                                 
  216.     fileSize = GetFileSize(filePointer, 0&)
  217.     Label7.Caption = fileSize
  218.     CloseHandle (filePointer)
  219. End Sub
  220.