我有一个脚本,它为根目录c:\ test中的所有文件夹创建一个名为'pst'的子文件夹。我需要在此脚本中添加哪些代码才能隐藏“pst”文件夹?
folder_path = "c:\test"
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(folder_path)
For each f in folder.SubFolders
fso.CreateFolder(f & "\PST")
next
非常感谢任何帮助。
答案 0 :(得分:2)
您需要做的就是使用文件夹属性。
Const Directory = 16
Const Hidden = 2
folder_path = "c:\test"
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(folder_path)
For each f in folder.SubFolders
With fso.CreateFolder(fso.BuildPath(f, "PST")) 'returns folder object
.Attributes = Directory Or Hidden 'set hidden flag for directory
End With
Next
答案 1 :(得分:1)
您可以尝试这样的事情:
Option Explicit
Dim fso,folder_path,folder,f
folder_path = "c:\test"
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(folder_path)
For each f in folder.SubFolders
'wscript.echo f & "\PST"
If Not fso.FolderExists(f & "\PST") Then
fso.CreateFolder(f & "\PST")
Call Hide(f & "\PST")
End If
If fso.FolderExists(f & "\PST") Then
Call Hide(f & "\PST")
End If
Next
'**********************************************
Sub Hide(MyFolder)
Dim Command,Result,Ws
Command = "Cmd /c attrib +h " & DblQuote(MyFolder) &""
'wscript.echo Command
Set Ws = CreateObject("Wscript.Shell")
Result = Ws.Run(Command,0,True)
End Sub
'**********************************************
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'**********************************************