Microsoft Scripting Runtime #3

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    Microsoft Scripting Runtime #3

    This is the 3rd in a series of Tips dealing specifically with the Microsoft Scripting Runtime Library. In this Tip, we'll show you how to return specific Properties relating to Files, as well as various Methods to Copy, Move, and Delete them. The code is self explanatory, so I'll jump right in:
    [CODE=vb]
    Dim fso As FileSystemObjec t, fil As File
    'Set fso = New Scripting.FileS ystemObject OR

    Set fso = CreateObject("S cripting.FileSy stemObject")

    Set fil = fso.GetFile("C: \Windows\System 32\Calc.exe")

    Debug.Print "File Created on: " & fil.DateCreated
    Debug.Print "File Size: " & FormatNumber(fi l.Size, 0) & " bytes"
    Debug.Print "File Drive: " & fil.Drive
    Debug.Print "File Name: " & fil.Name 'OR
    Debug.Print "File Name: " & fso.getFileName (fil)
    Debug.Print "File Last Modified: " & fil.DateLastMod ified
    Debug.Print "File Last Accessed: " & fil.DateLastAcc essed
    Debug.Print "File Parent Folder: " & fil.ParentFolde r
    Debug.Print "File Type: " & fil.Type
    Debug.Print "File Path: " & fil.path
    Debug.Print "File Short Name: " & fil.ShortName
    Debug.Print "File Short Path: " & fil.ShortPath
    Debug.Print "File Extension: " & fso.GetExtensio nName(fil)
    Debug.Print "File Version: " & fso.GetFileVers ion(fil)

    'To Copy a File (Copy C:\Windows\Syst em32\Calc.exe ==> C:\Dell\Copy.ex e)
    fil.Copy ("C:\Dell\Copy. exe") 'OR
    fso.CopyFile "C:\Windows\Sys tem32\Calc.exe" , "C:\Dell\Copy.e xe", True

    'To Delete a File (C:\Dell\IP.txt )
    Set fil = fso.GetFile("C: \Dell\IP.txt")
    fil.Delete True 'OR
    fso.DeleteFile "C:\Dell\IP.txt ", True

    'To Move a File (C:\Dell\Move_F rom.txt ==> C:\Test\Move_To .txt
    Set fil = fso.GetFile("C: \Dell\Move_From .txt")
    fil.Move "C:\Test\Move_T o.txt" 'OR
    fso.MoveFile "C:\Dell\Move_F rom.txt", "C:\Test\Move_T o.txt"[/CODE]
    File Properties OUTPUT:
    [CODE=text]
    File Created on: 9/11/2007 2:18:54 PM
    File Size: 114,688 bytes
    File Drive: C:
    File Name: calc.exe
    File Name: calc.exe
    File Last Modified: 8/4/2004 5:00:00 AM
    File Last Accessed: 2/15/2008 11:30:31 AM
    File Parent Folder: C:\WINDOWS\syst em32
    File Type: Application
    File Path: C:\WINDOWS\syst em32\calc.exe
    File Short Name: Calc.exe
    File Short Path: C:\Windows\Syst em32\Calc.exe
    File Extension: exe
    File Version: 5.1.2600.0[/CODE]
Working...