2011-09-03 106 views
0

我是批量腳本編程的新手。我想以編程方式瀏覽文件夾,然後將當前目錄的內容複製到指定的目錄。瀏覽文件夾的批量命令

我有一個VBScript腳本(下),允許我瀏覽一個文件夾。如何將批處理文件與它鏈接?也就是說,在腳本運行並選擇一個文件夾後,應將文件移動到選定的文件夾。可能嗎?

這裏是我的瀏覽文件夾VBScript代碼:

Option Explicit 

WScript.Echo BrowseFolder("C:\Program Files", True) 
WScript.Echo BrowseFolder("My Computer", False) 
WScript.Echo BrowseFolder("", False) 


Function BrowseFolder(myStartLocation, blnSimpleDialog) 
' This function generates a Browse Folder dialog 
' and returns the selected folder as a string. 
' 
' Arguments: 
' blnSimpleDialog [boolean] if False, an additional text field will be 
'        displayed where the folder can be selected 
'        by typing the fully qualified path 
' 
' Returns:   [string] the fully qualified path to the selected folder 
' 
' Based on the Hey Scripting Guys article 
' "How Can I Show Users a Dialog Box That Only Lets Them Select Folders?" 
' http://www.microsoft.com/technet/scriptcenter/resources/qanda/jun05/hey0617.mspx 
' 
' Function written by Rob van der Woude 
' http://www.robvanderwoude.com 
    Const MY_COMPUTER = &H11& 
    Const WINDOW_HANDLE = 0 ' Must ALWAYS be 0 

    Dim numOptions, objFolder, objFolderItem 
    Dim objPath, objShell, strPath, strPrompt 

    ' Set the options for the dialog window 
    strPrompt = "Select a folder:" 
    If blnSimpleDialog = True Then 
    numOptions = 0  ' Simple dialog 
    Else 
     numOptions = &H10& ' Additional text field to type folder path 
    End If 

    ' Create a Windows Shell object 
    Set objShell = CreateObject("Shell.Application") 

    ' If specified, convert "My Computer" to a valid 
    ' path for the Windows Shell's BrowseFolder method 
    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) 

    ' Quit if no folder was selected 
    If objFolder Is Nothing Then 
     BrowseFolder = "" 
     Exit Function 
    End If 

    ' Retrieve the path of the selected folder 
    Set objFolderItem = objFolder.Self 
    objPath = objFolderItem.Path 

    ' Return the path of the selected folder 
    BrowseFolder = objPath 
End Function 
+0

http://stackoverflow.com/questions/3470880/move-folder-from-one-目錄到另一個功能於批處理腳本 – 2011-09-03 09:31:36

回答

0

你想爲你做使用相同的功能批次您的VBScript?如果是這樣,我不認爲你可以批量使用OpenFileDialog,使用Visual Studio和C#很容易(值得一看)。如果你想這樣做批量,你可以這樣做:

set /p path=Enter folder path: 
xcopy /e %cd% %path% 
0

如果你真的想使用批處理您可以將值傳遞給環境變量或將其寫入io.out管道的價值了,但這些都不可取。您也可以將該值寫入臨時文本文件,並將您的批量用作輸入。 最好也是最簡單的解決方案是在腳本本身進行復制,爲此提供了大量樣本,還​​有更多可能對錯誤條件做出響應。 讓我知道,如果你找不到一個,我有一個在使用,但需要在發佈之前剝離一些數據..