I have following batch script to open a file selection dialog box from which I need to get name and path of selected file(my OS is Windows 7 64Bit
):
@echo off
setlocal
> "%temp%\fileSelectorDialog.vbs" (
echo DIM objFile
echo Set objShell = CreateObject^( "Shell.Application" ^)
echo Do
echo Set objFile = objShell.BrowseForFolder^(0,"Select a file",^&H4000,""^)
echo on error resume next
echo if objFile.Items.Item.Path = Null OR objFile is nothing OR err.number ^<^> 0 then
echo wscript.echo "ERROR"
echo wscript.quit
echo end if
echo wscript.echo objFile.ParentFolder.ParseName^(objFile.Title^).path
echo if instr^(objFile.items.item.path,"."^)^>0 then
echo wscript.echo objFile.Items.Item.Path
echo wscript.quit
echo end if
echo Msgbox "Please try again to choose a file rather than a folder. " ^& objFile.items.item.path
echo Loop
)
set file=ERROR
for /f "tokens=*" %%a in ('cscript //nologo "%temp%\fileSelectorDialog.vbs"') do set file=%%a
if "%file%"=="ERROR" (
echo There was an error or you cancelled
) ELSE (
echo Path chosen was %file%
)
pause
But this snippet only allows the basic "Computers" path as the initial directory to be opened when I trigger it, whereas I need to get my current directory (the directory in which script is executing) to be the initial directory when the file selection is triggered.
Can someone help me achieve this by Vbscript/Jscript or Powershell maybe ?