Connecting Tech Pros Worldwide Help | Site Map

Microsoft Scripting Runtime #3

ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,214
#1   Feb 15 '08
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:
Expand|Select|Wrap|Line Numbers
  1. Dim fso As FileSystemObject, fil As File
  2. 'Set fso = New Scripting.FileSystemObject    OR
  3.  
  4. Set fso = CreateObject("Scripting.FileSystemObject")
  5.  
  6. Set fil = fso.GetFile("C:\Windows\System32\Calc.exe")
  7.  
  8. Debug.Print "File Created on: " & fil.DateCreated
  9. Debug.Print "File Size: " & FormatNumber(fil.Size, 0) & " bytes"
  10. Debug.Print "File Drive: " & fil.Drive
  11. Debug.Print "File Name: " & fil.Name    'OR
  12. Debug.Print "File Name: " & fso.getFileName(fil)
  13. Debug.Print "File Last Modified: " & fil.DateLastModified
  14. Debug.Print "File Last Accessed: " & fil.DateLastAccessed
  15. Debug.Print "File Parent Folder: " & fil.ParentFolder
  16. Debug.Print "File Type: " & fil.Type
  17. Debug.Print "File Path: " & fil.path
  18. Debug.Print "File Short Name: " & fil.ShortName
  19. Debug.Print "File Short Path: " & fil.ShortPath
  20. Debug.Print "File Extension: " & fso.GetExtensionName(fil)
  21. Debug.Print "File Version: " & fso.GetFileVersion(fil)
  22.  
  23. 'To Copy a File (Copy C:\Windows\System32\Calc.exe ==> C:\Dell\Copy.exe)
  24. fil.Copy ("C:\Dell\Copy.exe")       'OR
  25. fso.CopyFile "C:\Windows\System32\Calc.exe", "C:\Dell\Copy.exe", True
  26.  
  27. 'To Delete a File (C:\Dell\IP.txt)
  28. Set fil = fso.GetFile("C:\Dell\IP.txt")
  29. fil.Delete True     'OR
  30. fso.DeleteFile "C:\Dell\IP.txt", True
  31.  
  32. 'To Move a File (C:\Dell\Move_From.txt ==> C:\Test\Move_To.txt
  33. Set fil = fso.GetFile("C:\Dell\Move_From.txt")
  34. fil.Move "C:\Test\Move_To.txt"      'OR
  35. fso.MoveFile "C:\Dell\Move_From.txt", "C:\Test\Move_To.txt"
File Properties OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. File Created on: 9/11/2007 2:18:54 PM
  2. File Size: 114,688 bytes
  3. File Drive: C:
  4. File Name: calc.exe
  5. File Name: calc.exe
  6. File Last Modified: 8/4/2004 5:00:00 AM
  7. File Last Accessed: 2/15/2008 11:30:31 AM
  8. File Parent Folder: C:\WINDOWS\system32
  9. File Type: Application
  10. File Path: C:\WINDOWS\system32\calc.exe
  11. File Short Name: Calc.exe
  12. File Short Path: C:\Windows\System32\Calc.exe
  13. File Extension: exe
  14. File Version: 5.1.2600.0



Reply


Similar Microsoft Access / VBA bytes