Wednesday 28 March 2007

Classic ASP - File Information

Paste the following code into an include file and use the GetFileAttribute function to return the attribute of that file, simple eh?

<%
'//Attribute List
'//==============
'// Windows 2000
'// ------------
'// Name, Size, Type, Modified, Attributes,
'// Comments, Created, Accessed, Owner, Author,
'// Title, Subject, Category, Pages, Copyright,
'// CompanyName, ModuleDescription, ModuleVersion,
'// ProductName, ProductVersion, SenderName, RecipientName,
'// RecipientNumber, CSID, TSID, TransmissionTime,
'// CallerID, Routing, AudioFormat, SampleRate,
'// AudioSampleSize, AudioChannels, PlayLength,
'// FrameCount, FrameRate, VideoSampleSize,
'// VideoCompression
'//
'// Win XP/2003
'// -----------
'// Name, Size, Type, Modified, Created, Accessed
'// Attributes, Status, Owner, Author, Title, Subject
'// Category, Pages, Comments, Copyright, Artist,
'// AlbumTitle, Year, TrackNumber, Genre, Duration,
'// BitRate, Protected, CameraModel, PictureDate,
'// Dimensions, Company, Description, Version,
'// ProductName, ProductVersion


function GetFileAttribute(filename, attribute)
dim srv, attrib
attrib = "error"
srv = Request.ServerVariables("SERVER_SOFTWARE")
if instr(srv,"/5.0")>0 then
'//Windows 2000 Machine
select case attribute
case "Name"
attrib = 0
case "Size"
attrib = 1
case "Type"
attrib = 2
case "Modified"
attrib = 3
case "Attributes"
attrib = 4
case "Comments"
attrib = 5
case "Created"
attrib = 6
case "Accessed"
attrib = 7
case "Owner"
attrib = 8
case "Author"
attrib = 10
case "Title"
attrib = 11
case "Subject"
attrib = 12
case "Category"
attrib = 13
case "Pages"
attrib = 14
case "Copyright"
attrib = 15
case "CompanyName"
attrib = 16
case "ModuleDescription"
attrib = 17
case "ModuleVersion"
attrib = 18
case "ProductName"
attrib = 19
case "ProductVersion"
attrib = 20
case "SenderName"
attrib = 21
case "RecipientName"
attrib = 22
case "RecipientNumber"
attrib = 23
case "CSID"
attrib = 24
case "TSID"
attrib = 25
case "TransmissionTime"
attrib = 26
case "CallerID"
attrib = 27
case "Routing"
attrib = 28
case "AudioFormat"
attrib = 29
case "SampleRate"
attrib = 30
case "AudioSampleSize"
attrib = 31
case "AudioChannels"
attrib = 32
case "PlayLength"
attrib = 33
case "FrameCount"
attrib = 34
case "FrameRate"
attrib = 35
case "VideoSampleSize"
attrib = 36
case "VideoCompression"
attrib = 37
end select

elseif instr(srv,"/5")>0 or instr(srv,"/6")>0 then
'//Windows XP/2003
select case attribute
case "Name"
attrib = 0
case "Size"
attrib = 1
case "Type"
attrib = 2
case "Modified"
attrib = 3
case "Created"
attrib = 4
case "Accessed"
attrib = 5
case "Attributes"
attrib = 6
case "Status"
attrib = 7
case "Owner"
attrib = 8
case "Author"
attrib = 9
case "Title"
attrib = 10
case "Subject"
attrib = 11
case "Category"
attrib = 12
case "Pages"
attrib = 13
case "Comments"
attrib = 14
case "Copyright"
attrib = 15
case "Artist"
attrib = 16
case "AlbumTitle"
attrib = 17
case "Year"
attrib = 18
case "TrackNumber"
attrib = 19
case "Genre"
attrib = 20
case "Duration"
attrib = 21
case "BitRate"
attrib = 22
case "Protected"
attrib = 23
case "CameraModel"
attrib = 24
case "PictureDate"
attrib = 25
case "Dimensions"
attrib = 26
case "Company"
attrib = 30
case "Description"
attrib = 31
case "Version"
attrib = 32
case "ProductName"
attrib = 33
case "ProductVersion"
attrib = 34
end select
end if

if IsNumeric(attrib) then
sFolder = left(filename,instrRev(filename,"\"))
sFile = right(filename, len(filename)-instrRev(filename,"\"))
Set oShell = CreateObject("Shell.Application")
Set oFolder = oShell.NameSpace(sFolder)
Set oFolderItem = oFolder.ParseName(sFile)
sInfo = oFolder.GetDetailsOf(oFolderItem, attrib)
If sInfo="" Then
GetFileAttribute=" "
Else
GetFileAttribute=sInfo
End If
else
GetFileAttribute=" "
end if

end function
%>


As an example, do the following:

GetFileAttribute(C:\myfile.txt, Created)

No comments: