create hidden txt file with vbs

半世苍凉 提交于 2019-12-08 01:12:42

问题


i currently have a vbscript that creates a txt file in a directory and opens it, but id like to make it so that the file is hidden, currtly i have this code:

Set objFSO=CreateObject("Scripting.FileSystemObject")

outFile="C:\Users\User\Desktop\New map"
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write "test line 1" & vbCrLf
objFile.Write "test line 2" & vbCrLf
objFile.Close

CreateObject("WScript.Shell").Run("""C:\Users\User\Desktop\New map""")

回答1:


You can set the attribute like this

Const cHidden = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")

outFile = "C:\Users\User\Desktop\New map"
Set objFile = objFSO.CreateTextFile(outFile, True)
objFile.Write "test line 1" & vbCrLf
objFile.Write "test line 2" & vbCrLf
objFile.Close

Set mapFile = objFSO.GetFile(outFile)
mapFile.Attributes = cHidden

CreateObject("WScript.Shell").Run Chr(34) & outFile & Chr(34)

Quick Reference --> https://www.thevbprogrammer.com/ch06/06-09-fso.htm https://ss64.com/vb/filesystemobject.html



来源:https://stackoverflow.com/questions/53635108/create-hidden-txt-file-with-vbs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!