AskDirectory not respecting New Folder name

Started by stevengraff, January 09, 2014, 06:28:31 PM

Previous topic - Next topic

stevengraff

Using AskDirectory, I create a new folder, then give it a name. When I click OK, WB thinks I want to use c:\apps\new folder. Any fix or workaround for this?

Please see http://screencast.com/t/SysSZkUm

This is on Server 2008 R2 Terminal Server, WB 2008B

td

This is an example of one of the several bugs in the underlying Windows shell API functions on Windows 7 (2008 R2) that WinBatch uses to create the the AskDirectory dialog.  MSFT has never addressed this problem. 

You could add the confirmation flag (2) to your call to AskDirectory and this would at least make it obvious that the new directory name is not being returned.  Another approach is to make sure that you change the selection to another folder after creating a new folder and then reselect the newly created folder.  Admittedly, neither of these suggestions completely solves the problem but there may be some other workaround out there that better addresses the issue.

There is a change request to rewrite the function for Windows 7 and newer systems using completely different shell APIs.  Doing so will change both the appearance and behavior of the function and its dialog on newer systems and may break backward comparability. But at some point we will need to make that change.
   
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stevengraff

Ok, well, at least we know what's going on.

Is there maybe some way to get in the middle of the process, analyze the return string for the presence of "New Folder" and return back to the dir picker all in the twinkle of an eye, i.e. immediately?

Maybe it's safest just to remove the New Folder creation option.

td

Quote from: stevengraff on January 10, 2014, 07:50:30 AM
Is there maybe some way to get in the middle of the process, analyze the return string for the presence of "New Folder" and return back to the dir picker all in the twinkle of an eye, i.e. immediately?

If you are referring to something that can be done in the implementation in WinBatch, no it is not an acceptable or effective solution for multiple reasons.  Many possible solutions have been investigated and the one mentioned in the previous post is by far the best.  You could, however,  check for "New Folder" in you script, assume that the user doesn't actually want to create a folder with that name and redisplay the dialog, if you want.   
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

Deana

This appears to be a bug in Windows 7: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/Win7+AskDirectory~in~Windows~7~Ignores~New~Folder.txt

Maybe give this Use Defined Function a try. I tested on Windows 7 and was able to successfully create a new folder under Program Files (x86).
Code (winbatch) Select

#DefineFunction udfAskDirectory(sTitle, iOptions, RootFolder )
   ; Deana Falk - November 13th 2009
   ; Reference: http://msdn.microsoft.com/en-us/library/bb774065(VS.85).aspx
   ; iOptions options for the dialog box. This member can be 0 or a combination of the following values.
   ; Version numbers refer to the minimum version of Shell32.dll required for SHBrowseForFolder to recognize
   ; flags added in later releases. See Shell and Common Controls Versions for more information.
   ;   BIF_RETURNONLYFSDIRS = 1; 0x00000001. Only return file system directories. If the user selects folders that are not part of the file system, the OK button is grayed. Note  The OK button remains enabled for "\\server" items, as well as "\\server\share" and directory items. However, if the user selects a "\\server" item, passing the PIDL returned by SHBrowseForFolder to SHGetPathFromIDList fails.
   ;   BIF_DONTGOBELOWDOMAIN = 2; 0x00000002. Do not include network folders below the domain level in the dialog box's tree view control.
   ;   BIF_STATUSTEXT = 4; 0x00000004. Include a status area in the dialog box. The callback function can set the status text by sending messages to the dialog box. This flag is not supported when BIF_NEWDIALOGSTYLE is specified.
   ;   BIF_RETURNFSANCESTORS = 8; 0x00000008. Only return file system ancestors. An ancestor is a subfolder that is beneath the root folder in the namespace hierarchy. If the user selects an ancestor of the root folder that is not part of the file system, the OK button is grayed.
   ;   BIF_EDITBOX = 16; 0x00000010. Version 4.71. Include an edit control in the browse dialog box that allows the user to type the name of an item.
   ;   BIF_VALIDATE = 32; 0x00000020. Version 4.71. If the user types an invalid name into the edit box, the browse dialog box calls the application's BrowseCallbackProc with the BFFM_VALIDATEFAILED message. This flag is ignored if BIF_EDITBOX is not specified.
   ;   BIF_NEWDIALOGSTYLE = 64; 0x00000040. Version 5.0. Use the new user interface. Setting this flag provides the user with a larger dialog box that can be resized. The dialog box has several new capabilities, including: drag-and-drop capability within the dialog box, reordering, shortcut menus, new folders, delete, and other shortcut menu commands. Note  If Component Object Model (COM) is initialized through CoInitializeEx with the COINIT_MULTITHREADED flag set, SHBrowseForFolder fails if BIF_NEWDIALOGSTYLE is passed.
   ;   BIF_BROWSEINCLUDEURLS = 128; 0x00000080. Version 5.0. The browse dialog box can display URLs. The BIF_USENEWUI and BIF_BROWSEINCLUDEFILES flags must also be set. If any of these three flags are not set, the browser dialog box rejects URLs. Even when these flags are set, the browse dialog box displays URLs only if the folder that contains the selected item supports URLs. When the folder's IShellFolder::GetAttributesOf method is called to request the selected item's attributes, the folder must set the SFGAO_FOLDER attribute flag. Otherwise, the browse dialog box will not display the URL.
   ;   BIF_USENEWUI = BIF_EDITBOX| BIF_NEWDIALOGSTYLE; Version 5.0. Use the new user interface, including an edit box. This flag is equivalent to BIF_EDITBOX | BIF_NEWDIALOGSTYLE. Note  If COM is initialized through CoInitializeEx with the COINIT_MULTITHREADED flag set, SHBrowseForFolder fails if BIF_USENEWUI is passed.
   ;   BIF_UAHINT = 256; 0x00000100. Version 6.0. When combined with BIF_NEWDIALOGSTYLE, adds a usage hint to the dialog box, in place of the edit box. BIF_EDITBOX overrides this flag.
   ;   BIF_NONEWFOLDERBUTTON = 512; 0x00000200. Version 6.0. Do not include the New Folder button in the browse dialog box.
   ;   BIF_NOTRANSLATETARGETS = 1024; 0x00000400. Version 6.0. When the selected item is a shortcut, return the PIDL of the shortcut itself rather than its target.
   ;   BIF_BROWSEFORCOMPUTER = 4096; 0x00001000. Only return computers. If the user selects anything other than a computer, the OK button is grayed.
   ;   BIF_BROWSEFORPRINTER = 8192; 0x00002000. Only allow the selection of printers. If the user selects anything other than a printer, the OK button is grayed. In Windows XP and later systems, the best practice is to use a Windows XP-style dialog, setting the root of the dialog to the Printers and Faxes folder (CSIDL_PRINTERS).
   ;   BIF_BROWSEINCLUDEFILES = ; 0x00004000. Version 4.71. The browse dialog box displays files as well as folders.
   ;   BIF_SHAREABLE = 16384; 0x00008000. Version 5.0. The browse dialog box can display shareable resources on remote systems. This is intended for applications that want to expose remote shares on a local system. The BIF_NEWDIALOGSTYLE flag must also be set.
   ;   BIF_BROWSEFILEJUNCTIONS = 65536; 0x00010000. Windows 7 and later. Allow folder junctions such as a library or a compressed file with a .zip file name extension to be browsed.
   objShell = CreateObject("Shell.Application")
   objFolder = objShell.BrowseForFolder(0, sTitle, iOptions, RootFolder)
   If ObjectTypeGet(objFolder) == "EMPTY" ||  ObjectTypeGet(objFolder) == "NULL"
       Pause("Notice","Unable to browse for directory, exiting script.")
       sPath = 0
       GoSub CleanupAndReturn
   EndIf
   If objFolder == 0
      Pause("Notice","User Cancelled the Dialog.")
      sPath = 0
   Else
      sPath = objFolder.Self.Path
   EndIf
   :CleanupAndReturn
   objFolder = 0
   objShell = 0
   Return sPath
#EndFunction


BIF_NEWDIALOGSTYLE = 64
DirAbs = udfAskDirectory("Browse for folder",BIF_NEWDIALOGSTYLE, "")
Pause('Result',DirAbs)
Exit


Reference: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/UDF~-~UDS~Library/Files~and~Directories+udfAskDirectory.txt
Deana F.
Technical Support
Wilson WindowWare Inc.

td

Quote from: Deana on January 10, 2014, 10:09:19 AM
This appears to be a bug in Windows 7: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/Win7+AskDirectory~in~Windows~7~Ignores~New~Folder.txt

As I mentioned in my original response in this topic, this problem is definitely a Windows 7 bug that will require a redo of the WinBatch 'AskDirectory' function in some future release.

The COM Automation server "Shell.Application" method is an excellent choice as a workaround.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade