CurrentModelInfo

The following example demonstrates how to use the File System Object to retrieve information about a file.

Example

Option Explicit

'------------------------------------------------------------------------------

' Subroutine: CurrentModelInfo

' Purpose:    Displays information about the currently loaded Rhino document.

'------------------------------------------------------------------------------

Sub CurrentModelInfo()

' Get the current document name and path

Dim strName, strPath, strFilespec

strName = Rhino.DocumentName()

strPath = Rhino.DocumentPath()

strFilespec = strPath & strName

Dim objFSO, objFile

' Get the file system object

Set objFSO = CreateObject("Scripting.FileSystemObject")

If (objFSO.FileExists(strFilespec)) Then

Set objFile = objFSO.GetFile(strFilespec)

' Display the file's information

PrintFileInformation(objFile)

Else

Rhino.Print "Current model not found. Make sure the model has been saved to disk."

End If

End Sub

 

'------------------------------------------------------------------------------

' Subroutine: PrintFileInformation

' Purpose:    Displays a file's information.

'------------------------------------------------------------------------------

Sub PrintFileInformation (objFile)

Dim str

str = "Full Path:  " & objFile.Path & vbCrLf

str = str & "File Name:  " & objFile.Name & vbCrLf

str = str & "File Type:  " & objFile.Type & vbCrLf

str = str & "File Attributes:  " & FileAttributes(objFile) & vbCrLf

str = str & "Date Created:  " & objFile.DateCreated & vbCrLf

str = str & "Last Date Accessed:  " & objFile.DateLastAccessed & vbCrLf

str = str & "Last Date Modified:  " & objFile.DateLastModified & vbCrLf

str = str & "File Size (Bytes):  " & objFile.Size & vbCrLf

Rhino.MessageBox str,,"Current Model Information"

End Sub

 

'------------------------------------------------------------------------------

' Function:   FileAttributes

' Purpose:    Returns a string describing a file's attributes.

'------------------------------------------------------------------------------

Function FileAttributes (objFile)

Dim str

If objFile.Attributes and 0 Then

str = "Normal"

Else

If objFile.Attributes and 1 Then str = str & "Directory "

If objFile.Attributes and 2 Then str = str & "Read-Only "

If objFile.Attributes and 4 Then str = str & "Hidden "

If objFile.Attributes and 8 Then str = str & "System "

If objFile.Attributes and 16 Then str = str & "Volume "

If objFile.Attributes and 32 Then str = str & "Archive "

If objFile.Attributes and 64 Then str = str & "Alias "

If objFile.Attributes and 128 Then str = str & "Compressed "

End If

FileAttributes = str

End Function