home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / ch_code / ch12 / fileinfo / fileinfo.frm (.txt) next >
Encoding:
Visual Basic Form  |  1997-02-20  |  5.3 KB  |  143 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.1#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        =   327680
  19.       FontSize        =   1.17491e-38
  20.    End
  21.    Begin VB.Frame Frame1 
  22.       Caption         =   "File Attributes"
  23.       Height          =   1815
  24.       Left            =   120
  25.       TabIndex        =   1
  26.       Top             =   120
  27.       Width           =   5655
  28.       Begin VB.Label Label7 
  29.          Height          =   255
  30.          Left            =   1080
  31.          TabIndex        =   7
  32.          Top             =   1320
  33.          Width           =   2895
  34.       End
  35.       Begin VB.Label Label6 
  36.          Height          =   255
  37.          Left            =   1560
  38.          TabIndex        =   6
  39.          Top             =   840
  40.          Width           =   2775
  41.       End
  42.       Begin VB.Label Label5 
  43.          Height          =   255
  44.          Left            =   1320
  45.          TabIndex        =   5
  46.          Top             =   360
  47.          Width           =   4215
  48.       End
  49.       Begin VB.Label Label3 
  50.          Caption         =   "File Size:"
  51.          Height          =   255
  52.          Left            =   120
  53.          TabIndex        =   4
  54.          Top             =   1320
  55.          Width           =   855
  56.       End
  57.       Begin VB.Label Label2 
  58.          Caption         =   "File Attribute:"
  59.          Height          =   255
  60.          Left            =   120
  61.          TabIndex        =   3
  62.          Top             =   840
  63.          Width           =   1095
  64.       End
  65.       Begin VB.Label Label1 
  66.          Caption         =   "File Name:"
  67.          Height          =   255
  68.          Left            =   120
  69.          TabIndex        =   2
  70.          Top             =   360
  71.          Width           =   975
  72.       End
  73.    End
  74.    Begin VB.CommandButton Command1 
  75.       Caption         =   "Get File Info"
  76.       Height          =   495
  77.       Left            =   1800
  78.       TabIndex        =   0
  79.       Top             =   2280
  80.       Width           =   2415
  81.    End
  82. Attribute VB_Name = "Form1"
  83. Attribute VB_GlobalNameSpace = False
  84. Attribute VB_Creatable = False
  85. Attribute VB_PredeclaredId = True
  86. Attribute VB_Exposed = False
  87. Option Explicit
  88. Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" _
  89.     (ByVal lpFileName As String) As Long
  90. Private Declare Function GetFullPathName Lib "kernel32" Alias "GetFullPathNameA" _
  91.     (ByVal lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, _
  92.     ByVal lpFilePart As String) As Long
  93. Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
  94.     (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, _
  95.     ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Any, _
  96.     ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, _
  97.     ByVal hTemplateFile As Long) As Long
  98. Private Declare Function GetFileSize Lib "kernel32" _
  99.     (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
  100. Private Declare Function CloseHandle Lib "kernel32" _
  101.     (ByVal hObject As Long) As Long
  102. Const FILE_ATTRIBUTE_ARCHIVE = &H20
  103. Const FILE_ATTRIBUTE_COMPRESSED = &H800
  104. Const FILE_ATTRIBUTE_DIRECTORY = &H10
  105. Const FILE_ATTRIBUTE_HIDDEN = &H2
  106. Const FILE_ATTRIBUTE_NORMAL = &H80
  107. Const FILE_ATTRIBUTE_READONLY = &H1
  108. Const FILE_ATTRIBUTE_SYSTEM = &H4
  109. Const GENERIC_READ = &H80000000
  110. Const OPEN_EXISTING = 3
  111. Const GENERIC_WRITE = &H40000000
  112. Private Sub Command1_Click()
  113.     Dim retValue As Long
  114.     Dim filePath As String * 255
  115.     Dim attrFlag As Long
  116.     Dim attrStr As String
  117.     Dim fileName As String
  118.     Dim filePointer As Long
  119.     Dim fileSize As Long
  120.     CommonDialog1.ShowOpen
  121.     If CommonDialog1.fileName <> "" Then fileName = CommonDialog1.fileName
  122.     'Get full path for file name
  123.     retValue = GetFullPathName(fileName, 255, filePath, 0)
  124.     Label5.Caption = filePath
  125.     'Get file attributes
  126.     attrFlag = GetFileAttributes(fileName)
  127.     If (attrFlag And FILE_ATTRIBUTE_ARCHIVE) Then attrStr = "A"
  128.     If (attrFlag And FILE_ATTRIBUTE_COMPRESSED) Then attrStr = attrStr & "C"
  129.     If (attrFlag And FILE_ATTRIBUTE_DIRECTORY) Then attrStr = attrStr & "D"
  130.     If (attrFlag And FILE_ATTRIBUTE_HIDDEN) Then attrStr = attrStr & "H"
  131.     If (attrFlag And FILE_ATTRIBUTE_NORMAL) Then attrStr = attrStr & "N"
  132.     If (attrFlag And FILE_ATTRIBUTE_READONLY) Then attrStr = attrStr & "R"
  133.     If (attrFlag And FILE_ATTRIBUTE_SYSTEM) Then attrStr = attrStr & "S"
  134.     Label6.Caption = attrStr
  135.     'Get file size
  136.     filePointer = CreateFile(fileName, GENERIC_READ Or GENERIC_WRITE, 0&, 0&, OPEN_EXISTING, _
  137.                                 FILE_ATTRIBUTE_NORMAL, 0&)
  138.                                 
  139.     fileSize = GetFileSize(filePointer, 0&)
  140.     Label7.Caption = fileSize
  141.     CloseHandle (filePointer)
  142. End Sub
  143.