0

I'm new to batch scripting. I want to programmatically browse for a folder and then copy the contents of current directory to the specified directory.

I have a VBScript script (below) that allows me to browse for a folder. How can I link the batch file with it? That is, after the script is run and a folder is selected, the files should be moved to the selected folder. Is it possible?

Here's my VBScript code for browsing for a folder:

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
alain.janinm
  • 19,951
  • 10
  • 65
  • 112
MithunSKR
  • 11
  • 1
  • 2
  • 3
  • http://stackoverflow.com/questions/3470880/move-folder-from-one-directory-to-another-in-batch-script –  Sep 03 '11 at 09:31

2 Answers2

0

If you realy want to use a batch you can pass the value to an environment variable or write it to io.out to pipe the value out but none of these is advisable. You could also write the value to a temporary textfile and have your batch use that as imput. Best and most simplest solution is to do the copying in your script itself, plenty of samples for that, more possibilities to respond to erro conditions too. Let me know if you can't find one, i have one in use but need to strip some data before publishing..

peter
  • 41,770
  • 5
  • 64
  • 108
0

Do you want to use the same function in batch as you do with your VBScript? If so I don't think you can use the OpenFileDialog with batch, very easy with Visual Studio and C# (worth looking at). If you want to do it in batch you could use this:

set /p path=Enter folder path: 
xcopy /e %cd% %path%
Bali C
  • 30,582
  • 35
  • 123
  • 152