File creation by using Vb script
I need a VB script which will create text file named "listitem" in C:\Documents and Settings\All Users\Application Data\secon\smartapp up to C:\Documents and Settings\All Users\Appli开发者_如何转开发cation Data\ we can make it as 'CommonAppDataFolder'
Any one knows about this
OK, let's see if I can remember how to do this...
Dim fso 'As Scripting.FileSystemObject
Dim stream 'As Scripting.TextStream
Set fso = CreateObject("Scripting.FileSystemObject")
'Check that the secon folder exists
If fso.FolderExists("C:\Documents and Settings\All Users\Application Data\secon") Then
Else
fso.CreateFolder("C:\Documents and Settings\All Users\Application Data\secon")
End If
'Check that the smartapp folder exists
If fso.FolderExists("C:\Documents and Settings\All Users\Application Data\secon\smartapp") Then
Else
fso.CreateFolder("C:\Documents and Settings\All Users\Application Data\secon\smartapp")
End If
'Create the file as ASCII text, overwrite it if it already exists
Set stream = fso.CreateTextFile("C:\Documents and Settings\All Users\Application Data\secon\smartapp\listitem.txt", true, false)
'Close it neatly
stream.Close
'Clean up
Set stream = Nothing
Set fso = Nothing
Here're some tips for you:
- To obtain the CommonAppData path programmatically, use the
Shell.Namespace(35)
method. (35 is the folder id according to the ShellSpecialFolderConstants Enumeration.) See this question for an example. - To concatenate two paths, use the
FileSystemObject.BuildPath
method. - To create text files, you can use the
FileSystemObject.CreateTextFile
method.
Hope you can manage the rest yourself. :)
精彩评论