The folders accessible with this function include AllUsersDesktop,
AllUsersStartMenu, AllUsersPrograms, AllUsersStartup, Desktop, Favorites,
Fonts, MyDocuments, NetHood, PrintHood, Programs, Recent, SendTo,
StartMenu, Startup, and Templates. See ???Wacky Script Ideas,??? later in this
chapter, for further examples.
Function GetSpecialFolder(Foldername)
set WshShell = WScript.CreateObject("WScript.Shell")
GetSpecialFolder = WshShell.SpecialFolders(Foldername)
End Function
Function GetSystemFolder( )
Set FileObject = CreateObject("Scripting.FileSystemObject")
GetSystemFolder = FileObject.GetSpecialFolder(1) & "\"
End Function
Function GetTempFilename( )
Set FileObject = CreateObject("Scripting.FileSystemObject")
GetTempFile = FileObject.GetSpecialFolder(2) & "\" _
& FileObject.GetTempName
End Function
Function GetWindowsFolder( )
Set FileObject = CreateObject("Scripting.FileSystemObject")
GetWindowsFolder = FileObject.GetSpecialFolder(0) & "\"
End Function
While the previous functions and subroutines are used to manipulate files,
the following two manipulate the contents of files. The ReadFromFile function
will transfer the contents of any file into a variable (naturally, this is
530 | Chapter 9: Scripting and Automation
most useful with plain-text files). Likewise, the WriteToFile subroutine will
transfer the contents of a variable (specified as Text) into a file. If the file
doesn??™t exist, it will be created; if the file already exists, the text will be
appended to the end of the file:
Function ReadFromFile(Filename)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set FileObject = CreateObject("Scripting.
Pages:
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737