Skip to content

Latest commit

 

History

History
79 lines (61 loc) · 2.75 KB

sample_178.md

File metadata and controls

79 lines (61 loc) · 2.75 KB

Home

Using Path functions from Shell Lightweight Utility APIs (shlapi.dll)

Code:

DO decl

LOCAL lcComponent, lcFullPath, lnPointer
lcFullPath = "C:\Program Files\Microsoft Office\Office\Binder.exe"

? "Source path string:", lcFullPath

? "File exists:", Iif(PathFileExists(lcFullPath)=0, "No","Yes")
? "Path is directory:", Iif(PathIsDirectory(lcFullPath)=0, "No","Yes")

* e.g. "prgs\tx0.prg"
? "Path is relative:", Iif(PathIsRelative(lcFullPath)=0, "No", "Yes")

* e.g. "C:\"
? "Path is root:", Iif(PathIsRoot(lcFullPath)=0, "No", "Yes")

* e.g. "http://www.news2news.com/vfp/downloads/"
? "Path is URL:", Iif(PathIsURL(lcFullPath)=0, "No", "Yes")

* any mapped network drive, or a network name like "\\prnserver"
? "A network resource:", Iif(PathIsNetworkPath(lcFullPath)=0, "No","Yes")

? "File name:", PathFindFileName(lcFullPath)
? "File extension:", PathFindExtension(lcFullPath)

lcComponent = lcFullPath
= PathRenameExtension (@lcComponent, ".inf")
? "With extension replaced:", lcComponent

* Returns 0 through 25 (corresponding to "A" through "Z")
* if the path has a drive letter, or -1 otherwise
? "Drive number:", PathGetDriveNumber(lcFullPath)

? "Root directories: "
FOR ii=0 TO 25
	lcComponent = SPACE(250)
	IF PathBuildRoot(@lcComponent, ii) <> 0
		?? Left(lcComponent, AT(Chr(0), lcComponent)-1)+" "
	ENDIF
ENDFOR

PROCEDURE  decl
	DECLARE STRING  PathFindFileName IN shlwapi STRING pPath
	DECLARE INTEGER PathFileExists IN shlwapi STRING pszPath
	DECLARE INTEGER PathIsDirectory IN shlwapi STRING pszPath
	DECLARE INTEGER PathIsRelative IN shlwapi STRING pszPath
	DECLARE INTEGER PathIsRoot IN shlwapi STRING pszPath
	DECLARE INTEGER PathIsURL IN shlwapi STRING pszPath
	DECLARE INTEGER PathIsNetworkPath IN shlwapi STRING pszPath
	DECLARE STRING  PathFindExtension IN shlwapi STRING pPath
	DECLARE INTEGER PathGetDriveNumber IN shlwapi STRING lpsz

	DECLARE INTEGER PathRenameExtension IN shlwapi;
		STRING @pszPath, STRING pszExt

	DECLARE INTEGER PathBuildRoot IN shlwapi;
		STRING @szRoot, INTEGER iDrive  

Listed functions:

PathBuildRoot
PathFileExists
PathFindExtension
PathFindFileName
PathGetDriveNumber
PathIsDirectory
PathIsNetworkPath
PathIsRelative
PathIsRoot
PathIsURL
PathRenameExtension