Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving file properties 2

Status
Not open for further replies.

plsh

Programmer
Mar 5, 2003
118
ZA
Good day,

Does anyone know how to retrieve the file properties for a text file with VB. I need to know when the file was created.

Thanks in advance
 
Here is the structure and the API call:

Private Type BY_HANDLE_FILE_INFORMATION
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
dwVolumeSerialNumber As Long
nFileSizeHigh As Long
nFileSizeLow As Long
nNumberOfLinks As Long
nFileIndexHigh As Long
nFileIndexLow As Long
End Type

Private Declare Function GetFileInformationByHandle Lib "kernel32" Alias "GetFileInformationByHandle" (ByVal hFile As Long, lpFileInformation As BY_HANDLE_FILE_INFORMATION) As Long


Please enjoy ....... Greg.

"Life is full of learning, and then there is wisdom"
 
and .... FILETIME is

Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

and also ....

FILETIME
The FILETIME data structure is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601. It is the means by which Win32 determines the date and time. FILETIME is used by the CoDosDateTimeToFileTime, CoFileTimeToDosDateTime, and CoFileTimeNow functions. It is defined as follows:

typedef struct STRUCT tagFILETIME
{
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} FILETIME;

Members
dwLowDateTime
The low 32 bits of the Win32 date/time value.
dwHighDateTime
The upper 32 bits of the Win32 date/time value.
Remarks
The FILETIME data structure is used in the time conversion functions between DOS and Win32.



"Life is full of learning, and then there is wisdom"
 
And here a one-liner (not that that necessarily makes it good code):
Code:
Debug.Print CreateObject("scripting.filesystemobject").GetFile("c:\demo.txt").DateCreated
 
Thanks to all of you,

I have found the answer which is:

sFileName = filename
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(sFileName)
Created = Format(objFile.DateCreated, "dd/mm/yyyy")
DateLastmodified=Format(objFile.DateLastmodified, "dd/mm/yyyy")

Set objFile = Nothing
Set objFSO = Nothing

Much the same as strongm, just a better coded version

Thanks
 
snowei1,
You should be able to do it the filesystemobject as specified above, but you'll have to pass the actual path name. You can't use the web address, as far as I know...

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
Hi snowie1,

You can get the modified date of a file on a web server provided you have a page on that server. The same code above with the FileSystemObject can be used and the code to retrieve the file can be something like:

sFile = " & <%=Request.ServerVariables("SERVER_NAME")%> & "/file.txt"

You can otherwise hard code the servername as you had in your question, but this is just better coding.

You may have to refine the location of the file but it does work as I use this code at the moment all the time.

Hope this helps.

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top