对文件的操作(FSO)
上一篇 /
下一篇 2011-07-22 14:46:55
/ 个人分类:QTP
'对文件的操作
Option Explicit
Dim LogFile,objFSO,objFile
LogFile="g:\FSO\fso.txt"
Const ForWriting=2
Const ForAppending=8
Set bjFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(LogFile) Then
Set bjFile = objFSO.OpenTextFile(LogFile, ForAppending)
objFile.Write "appending " & Now
Else
Set bjFile = objFSO.CreateTextFile(LogFile)
'objFile.Close
'Set bjFile = objFSO.OpenTextFile(LogFile, ForWriting)
objFile.write "writing to new file " & Now
End i
’文件夹操作
Option Explicit
Dim numFolders
Dim folderPath
Dim folderPrefix
Dim objFSO
Dim objFolder
Dim i
Dim objShell
Dim strDocPath
Set bjShell = CreateObject("WScript.Shell")
strDocPath = objShell.SpecialFolders("mydocuments")
numFolders = 10
folderPath = strDocPath & "\"
folderPrefix = "Student"
For i = 1 To numFolders
Set bjFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(folderPath & folderPrefix & i) Then
WScript.Echo(folderPath & folderPrefix & i & " exists." _
& " folder not created")
Else
Set bjFolder = objFSO.CreateFolder(folderPath & folderPreFix & i)
WScript.Echo(folderPath & folderPrefix & i & " folder created")
End If
Next
收藏
举报
TAG: