长期搜索者,第一次海报。
我已经整理了一个vb脚本,我的用户可以从资源管理器中运行该脚本,这将允许他们创建并命名新文件夹,然后将模板结构复制到新文件夹中。我使用了robocopy,因此复杂的文件夹权限将与模板一起复制,这是脚本背后的主要动机。
我绝不是vb的专家。很高兴在这里有任何关于这个脚本的建议,但是这个脚本很适合用户.....到目前为止无论如何!!!
SetobjShell = CreateObject("Wscript.Shell")
Call Entercompanyname
Function Entercompanyname
companyname = InputBox("Please enter the new company name" & vbLf & "(or select cancel to it)", _
"Create New Company Folder")
If IsEmpty(companyname) Then
Cancel = MsgBox("Are you sure you want to exit ?", 68, "Exit Application?")
If Cancel = vbYes Then
WScript.Quit
ElseIf Cancel = vbNo Then
Call Entercompanyname
End If
ElseIf Len(companyname) = 0 Then
MsgBox "You clicked OK but did not enter a new company name", 64, "Error: No Company Name entered"
Call Entercompanyname
End If
objSource = "\\serverxx\Data\Accounts\Accounting\company_template"
objDestination = ("\\serverxx\Data\Accounts\Accounting\" & companyname)
objCommand = "RoboCopy.Exe " & Chr(34) & objSource & Chr(34) & " " & Chr(34) & objDestination & Chr(34) & " /sec /e /r:1 /w:2"
objShell.Run(objCommand)
现在部门负责人回到我身边,并要求一个新的脚本,以便能够在每个公司名称中创建新的年份文件夹。我们将有一个新年的模板,但他们希望能够选择创建新年文件夹的公司。
有没有人有任何建议。
提前致谢!!
我被问到一个例子。我找到了这个,这就是我追逐的东西,但这只能让用户选择一家公司。所以这个过程需要重复,我知道这会引起戏剧
WScript.Echo BrowseFolder( "\\serverxx\Data\Accounts\Accounting", True )
Function BrowseFolder( myStartLocation, blnSimpleDialog )
Const MY_COMPUTER = &H11&
Const WINDOW_HANDLE = 0 ' Must ALWAYS be 0
Dim numOptions, objFolder, objFolderItem
Dim objPath, objShell, strPath, strPrompt
strPrompt = "Select a folder:"
If blnSimpleDialog = True Then
numOptions = 0 ' Simple dialog
Else
numOptions = &H10&
End If
Set objShell = CreateObject( "Shell.Application" )
If UCase( myStartLocation ) = "MY COMPUTER" Then
Set objFolder = objShell.Namespace( MY_COMPUTER )
Set objFolderItem = objFolder.Self
strPath = objFolderItem.Path
Else
strPath = myStartLocation
End If
Set objFolder = objShell.BrowseForFolder( WINDOW_HANDLE, strPrompt, _
numOptions, strPath )
If objFolder Is Nothing Then
BrowseFolder = ""
Exit Function
End If
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
End Function