-
Jan 29th, 2008, 11:42 PM
#1
Thread Starter
PowerPoster
[RESOLVED] How do get information on a file?
Hey guys I have a label2, is there a way to get the data a file was put on the computer for the labels caption, the file is in the same folder as the app.
Thanks!
-
Jan 30th, 2008, 12:38 AM
#2
Re: How do get information on a file?
You mean the date of a file?
Use the FileDateTime function to determine the date and time a file was created or last modified. The format of the date and time displayed is based on the locale settings of your system.
Label2 = FileDateTime("thefile.abc")
-
Jan 30th, 2008, 01:13 AM
#3
Thread Starter
PowerPoster
Re: How do get information on a file?
Thanks, BTW could to you tell me how to get the size of the file in KB?
-
Jan 30th, 2008, 02:21 AM
#4
Re: How do get information on a file?
Files size
Add a reference to the Microsoft Scripting Runtime.
Dim o As New FileSystemObject
Dim oFile As File
Set oFile = o.GetFile("c:\test.text")
MsgBox oFile.Size
or this way
MyLen = FileLen("C:\autoexec.bat")
MyDate = FileDateTime("C:\autoexec.bat")
or using api
Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = 3
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const FO_DELETE = &H3
Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Function MoveFile Lib "kernel32" Alias "MoveFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String) As Long
Private Declare Function CreateFile Lib "kernel32"
Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
------------------------------------
this the code:
Dim lngHandle As Long
lngHandle = CreateFile("C:\Divi.txt", GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
MsgBox "The size of the selected file is" + Str$(GetFileSize(lngHandle, lngLong)) + " bytes."
This will return the size of the file in Bytes
you can do conversion from Bytes to kb
Bytes = Bytes\1024 = kb
-
Jan 30th, 2008, 02:59 AM
#5
Re: How do get information on a file?
Another way might be to open the file and use the Lof function
Code:
Dim intFile As Integer
Dim sngLen As Single
intFile = FreeFile
Open "C:\Divi.txt" For Input As intFile
sngLen = CSng(Lof(intFile)) / CSng(1024)
Close intFile
Msgbox "File size is " & Format(sngLen, "####.00) & "Kb"
EDIT: I should point out that this will return the actual size of the file not necessarily the amount of disk space it occupies.
-
Jan 30th, 2008, 03:11 AM
#6
Re: How do get information on a file?
Originally Posted by Justin M
Thanks, BTW could to you tell me how to get the size of the file in KB?
Code:
Label2 = Format(FileLen("thefile.abc") / 1024, "#,### KB")
-
Jan 30th, 2008, 08:06 AM
#7
Re: How do get information on a file?
Another alternative is simply to open its very own property page
vb Code:
Private Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
lpIDList As Long 'Optional parameter
lpClass As String 'Optional parameter
hkeyClass As Long 'Optional parameter
dwHotKey As Long 'Optional parameter
hIcon As Long 'Optional parameter
hProcess As Long 'Optional parameter
End Type
Private Const SEE_MASK_INVOKEIDLIST = &HC
Private Const SEE_MASK_NOCLOSEPROCESS = &H40
Private Const SEE_MASK_FLAG_NO_UI = &H400
Private Declare Function ShellExecuteEx Lib "shell32.dll" (SEI As SHELLEXECUTEINFO) As Long
Private Sub ShowProperties(filename As String, OwnerhWnd As Long)
'open a file properties property page for
'specified file if return value
Dim SEI As SHELLEXECUTEINFO
'Fill in the SHELLEXECUTEINFO structure
With SEI
.cbSize = Len(SEI)
.fMask = SEE_MASK_NOCLOSEPROCESS Or _
SEE_MASK_INVOKEIDLIST Or _
SEE_MASK_FLAG_NO_UI
.hwnd = OwnerhWnd
.lpVerb = "properties"
.lpFile = filename
.lpParameters = vbNullChar
.lpDirectory = vbNullChar
.nShow = 0
.hInstApp = 0
.lpIDList = 0
End With
'call the API to display the property sheet
Call ShellExecuteEx(SEI)
End Sub
'Usage: Place the full path and file name in the text box
Private Sub Command1_Click()
Call ShowProperties((Text1.Text), Me.hwnd)
End Sub
-
Jan 30th, 2008, 08:31 PM
#8
Thread Starter
PowerPoster
Re: How do get information on a file?
-
Feb 2nd, 2008, 01:35 AM
#9
Thread Starter
PowerPoster
Re: [RESOLVED] How do get information on a file?
Oh instead of making a new thread since its pretty close to the same question..
I have a file on a website, and by using this code ..
Label2 = FileDateTime("thefile.abc")
How do I find the date of a file on a website? Thansk!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|