//  home   //  advanced search   //  news   //  categories   //  sql build chart   //  downloads   //  statistics
 ASP FAQ 
Home
ASP FAQ Tutorials

   8000XXXX Errors
   Alerts
   ASP.NET 2.0
   Classic ASP 1.0
      COM / ActiveX Components
      Forms
      General Topics
      Date/Time Routines
      Email Scripts & Info
      Files/Directories & FSO
   Databases
   General Concepts
   Search Engine Optimization (SEO)

Contact Us
Site Map

Search

Web
aspfaq.com
tutorials.aspfaq.com
classicasp.aspfaq.com

ASP FAQ Tutorials :: Classic ASP 1.0 :: Files/Directories & FSO :: How do I find the owner, author, and other properties of a file?


How do I find the owner, author, and other properties of a file?

Here's a little script that will list out the files in a folder, and show the filename, type, size, created/modified/accessed date, owner, and file attributes. This code has been tested on Windows 2000, Windows XP, and Windows Server 2003. 
 
<style>  
body,td,th { font-family:tahoma;font-size:8pt }  
</style>  
<% 
    filesz = 0 
    fileown = 8 
 
    srv = Request.ServerVariables("SERVER_SOFTWARE") 
    if instr(srv,"/5.0")>0 then 
 
        filesz = 1      
        filecr = 6 
        fileac = 7 
        fileat = 4              
 
    elseif instr(srv,"/5")>0 or instr(srv,"/6")>0 then 
         
        filesz = 1 
        filecr = 4 
        fileac = 5 
        fileat = 6 
 
    end if 
 
    if filesz > 0 then 
 
        folder = "c:\"  
 
        response.write "<b>File listing for " & folder & "</b><p>"  
        response.write "<table border=1 cellpadding=5 cellspacing=0>"  
        response.write "<tr>"  
        response.write "<th>Filename</th>"  
        response.write "<th>Type</th>"  
        response.write "<th>Size</th>"  
        response.write "<th>Created</th>"  
        response.write "<th>Modified</th>"  
        response.write "<th>Accessed</th>"  
        response.write "<th>Owner</th>"  
        response.write "<th>Attributes</th>"  
        response.write "</tr>"  
 
        tds = "<td><nobr> "  
        tde = " </nobr></td>"  
 
        Set sh = CreateObject("Shell.Application")  
        set fl = sh.Namespace(folder)  
 
        for each f in fl.Items  
            if not f.IsFolder then  
                p = f.path  
                fn = right(p, len(p)-instrRev(p,"\"))  
                response.write "<tr>" & _  
                tds & fn & tde & _  
                tds & f.type & tde & _  
                tds & fl.GetDetailsOf(f,filesz) & tde & _  
                tds & fl.GetDetailsOf(f,filecr) & tde & _  
                tds & f.modifyDate & tde & _  
                tds & fl.GetDetailsOf(f,fileac) & tde & _  
                tds & fl.GetDetailsOf(f,fileown) & tde & _  
                tds & fl.GetDetailsOf(f,fileat) & tde & _  
                "</tr>"  
            end if  
        next  
 
        set fl = nothing  
        set sh = nothing  
 
        response.write "</table>" 
    else 
        response.write "Unable to process results." 
    end if 
%>
 
You may need to make sure that IUSR_YourMachine (or the authenticated user) has appropriate access to the folder in question. Also, be aware that hidden or protected system files (such as boot.ini) won't be shown unless your machine is wide open. 
 
For some of the properties, you can merely use the FileSystemObject. For example, to get the size of a file: 
 
<% 
    thisFile = Request.ServerVariables("SCRIPT_NAME") 
    Set fso = CreateObject("Scripting.FileSystemObject") 
    Set file = fso.GetFile(Server.MapPath(thisFile)) 
    Response.Write "Size of file: " & file.size & " bytes, " & _ 
        formatnumber(file.size/1024, 2) & " KB" 
    Set file = nothing 
    Set fso = nothing 
%>
 
See Microsoft's site for official FileSystemObject documentation. You can also see Article #2039 for a marginal tutorial on FSO, as well as some tips on avoiding common pitfalls. 
 

 
Thanks to "Reverend Brad" for pointing me to the .path property, which at least put aside the mystery of the missing extensions that I encountered when initially putting together this article. 
 
Here is a full listing of the GetDetailsOf elements--they are different on Windows 2000 than on Windows XP / Windows Server 2003. If you want to write conditional code that will use the correct property set, depending on which operating system your ASP pages are deployed to, see Article #2130
 
Notice that some are particularly useful for Word or other MS Office documents. Note that Name doesn't always contain the extension, just in case you try to use it and don't understand why you get inconsistent results. 
 
    #Windows XP
    Windows Server 2003
    Windows 2000
    0NameName
    1SizeSize
    2TypeType
    3Date ModifiedDate Modified
    4Date CreatedAttributes
    5Date AccessedComment
    6AttributesDate Created
    7StatusDate Accessed
    8OwnerOwner
    9Author???
    10TitleAuthor
    11SubjectTitle
    12CategorySubject
    13PagesCategory
    14CommentsPages
    15CopyrightCopyright
    16ArtistCompany Name
    17Album TitleModule Desription
    18YearModule Version
    19Track NumberProduct Name
    20GenreProduct Version
    21DurationSender Name
    22Bit RateRecipient Name
    23ProtectedRecipient Number
    24Camera ModelCsid
    25Date Picture TakenTsid
    26DimensionsTransmission Time
    27???Caller Id
    28???Routing
    29???Audio Format
    30CompanySample Rate
    31DescriptionAudio Sample Size
    32File VersionChannels
    33Product NamePlay Length
    34Product VersionFrame Count
    35???Frame Rate
    36???Video Sample Size
    37???Video Compression

Related Articles

Can I include a file in both server-side and client-side script?
Can I read / write a user's file without a prompt?
Can I rename a file using FileSystemObject?
Could I get some help working with files using FileSystemObject?
How do I avoid 'the red x' when an image is missing?
How do I change the modified time of a file?
How do I create / manipulate images from ASP?
How do I dynamically include files?
How do I get a list of a folder's subfolders?
How do I get the name of the current URL / page?
How do I prevent people from 'leeching' my CSS or JS files?
How do I prevent people from 'leeching' my images?
How do I retrieve a random file from a given folder?
How do I send the correct filename with BinaryWrite?
How do I sort a list of files?
How do I use FileSystemObject to create a file on the client?
Why do I get 'Disk not ready' errors with FileSystemObject?
Why do I get 'Invalid procedure call or argument'?
Why do I get 'Path not found' errors with Scripting.FileSystemObject?
Why do I get 'Permission Denied' errors with FileSystemObject?
Why do I get 800A0034 errors?
Why do I get 800A003E / Input past end of file errors?
Why do I get 800A0BBA errors?
Why do I get 800A0BBC errors?
Why do I get an 'Invalid Path Character' error?
Why do I get permissions errors after upgrading to Windows XP?
Why does FileSystemObject hang all of a sudden?
Why is 'the operation completed successfully' an error message?

 

 


Created: 6/7/2002 | Last Updated: 3/24/2005 | broken links | helpful | not helpful | statistics
© Copyright 2006, UBR, Inc. All Rights Reserved. (320)

 

Copyright 1999-2006, All rights reserved.
Finding content
Finding content.  An error has occured...