Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Enhanced GETDIR() using Shell Object
Message
De
08/10/1998 07:47:14
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Titre:
Enhanced GETDIR() using Shell Object
Divers
Thread ID:
00144940
Message ID:
00144940
Vues:
48
I posted a FAQ entry last night that uses the Shell Object to provide a much stronger directory selector; I discovered a problem in that selecting an empty directory didn't return properly. The following revised code works, and has some additional detail on flag values:
FUNCTION SelDirDlg
LPARAMETERS cDialogTitle, cStartingFolder, nBrowseFlags
*  Select a directory using the default browser dialog
IF TYPE('cDialogTitle') # 'C'
	cDialogTitle = 'Please select a folder:'
ENDIF
IF TYPE('cStartingFolder') # 'C'
	cStartingFolder = FULLPATH(CURDIR())
ENDIF
IF TYPE('nBrowseFlags') # 'N'
	* uses BROWSEINFO structure ulFlags values
	* by default, set BIF_RETURNONLYFSDIRS (1) and BIF_EDITBOX (16) and BIF_VALIDATE (32)
	* to limit to returning directories, provide an edit box to let user enter a path,
	* and validate manually-entered paths
	*
	* ulFlags values:
	*	BIF_RETURNONLYFSDIRS	1
	*	BIF_DONTGOBELOWDOMAIN	2
	*	BIF_STATUSTEXT			4
	*	BIF_RETURNFSANCESTORS	8
	*	BIF_EDITBOX				0x10
	*	BIF_VALIDATE			0x20
	*	BIF_BROWSEFORCOMPUTER	0x1000
	*	BIF_BROWSEFORPRINTER	0x2000
	*	BIF_BROWSEFOREVERYTHING	0x4000
	nBrowseFlags = 32 + 16 + 1
ENDIF
LOCAL oBrowseObject, cPathToReturn, oShellObj
oShellObj = CREATEOBJ('Shell.Application')
cPathToReturn = ''
*	Get a Folder object
oBrowseObject = oShellObj.BrowseForFolder(0, ;
											cDialogTitle, ;
											nBrowseFlags, ;
											cStartingFolder)
*	Before I used the Items collection of the Folder object
*	to get a path;  it doesn't work if the directory is empty.
*	Instead, spin through the Items collection of the Parent
*	Folder and locate the item whose name matches the
*	Title property of the Folder object;  return that path
FOR EACH item IN oBrowseObject.ParentFolder.Items
   IF item.name == oBrowseObject.title
	   cPathToReturn = Item.Path
	   EXIT
   ENDIF
ENDFOR
RETURN cPathToReturn
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Répondre
Fil
Voir

Click here to load this message in the networking platform