如何使VBScript在下载文件夹中创建文本文件?
我想让VBScript在下载文件夹中创建一个文本文件,但我不知道该怎么做。如何使VBScript在下载文件夹中创建文本文件?,vbscript,Vbscript,我想让VBScript在下载文件夹中创建一个文本文件,但我不知道该怎么做。 有什么帮助吗?在文档中创建文本文件 Option Explicit Const FileName = "New.txt" Dim wss: Set wss = CreateObject("WScript.Shell") Dim FolderPath: FolderPath = wss.SpecialFolders("MyDocuments") Dim fs
有什么帮助吗?在文档中创建文本文件
Option Explicit
Const FileName = "New.txt"
Dim wss: Set wss = CreateObject("WScript.Shell")
Dim FolderPath: FolderPath = wss.SpecialFolders("MyDocuments")
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
Dim FilePath: FilePath = fso.BuildPath(FolderPath, FileName)
Dim fsoFile:Set fsoFile = fso.CreateTextFile(FilePath, True)
fsoFile.Close
获取文档文件夹路径
Option Explicit
Dim wss: Set wss = CreateObject("WScript.Shell")
Dim FolderPath: FolderPath = wss.SpecialFolders("MyDocuments")
MsgBox "Your documents folder is located in '" _
& Folderpath & "'.", vbInformation, "Documents"
Dim RunString: RunString = "explorer.exe /e," & FolderPath
wss.Run RunString
您可以通过以下方式获取临时文件夹:
Set ws = CreateObject("WScript.Shell")
TempFolder = ws.ExpandEnvironmentStrings("%Temp%")
整个vbscript可以按如下方式编写,以将文本文件创建到临时文件夹中:
Option Explicit
Dim ws,fso,TempFolder,FileFullPath,FileName,objFile
Set ws = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
TempFolder = ws.ExpandEnvironmentStrings("%Temp%")
FileName = "testfile.txt"
FileFullPath = TempFolder & "\" & FileName
wscript.echo "The Temparary folder is located : " & vbCrlf & TempFolder
wscript.echo "The Full Path of the text file is : " & vbCrlf & FileFullPath
Set objFile = fso.CreateTextFile(FileFullPath, True)
' Write something into text file
objFile.WriteLine("This is a test.")
objFile.Close
' If we want to open the text file created with Notepad
ws.run "Notepad " & FileFullPath
可在此处找到下载文件夹:
Set ws = CreateObject("WScript.Shell")
DownloadFolder = ws.ExpandEnvironmentStrings("%userprofile%") & "\Downloads"
wscript.echo DownloadFolder
以及在下载文件夹中创建文本文件的整个脚本:
Option Explicit
Dim ws,fso,DownloadFolder,FileFullPath,FileName,objFile
Set ws = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
DownloadFolder = ws.ExpandEnvironmentStrings("%userprofile%") & "\Downloads"
FileName = "testfile.txt"
FileFullPath = DownloadFolder & "\" & FileName
wscript.echo "The Download folder is located : " & vbCrlf & DownloadFolder
wscript.echo "The Full Path of the text file is : " & vbCrlf & FileFullPath
Set objFile = fso.CreateTextFile(FileFullPath, True)
' Write something into text file
objFile.WriteLine("This is a test.")
objFile.Close
' If we want to open the text file created with Notepad
ws.run "Notepad " & FileFullPath
这可能会对您有所帮助:-如果您使用的是
WScript
,请尝试以下操作:是否可以让它在再次运行文件时创建一个新的文本文件,而不是覆盖它?