Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: PathStripToRoot PathStripToRootA DllCall UDF shlwapi.dll
#DefineFunction PathStripToRoot(path) ;BOOL PathStripToRoot( LPTSTR szRoot); MAX_PATH = 260 bb = BinaryAlloc(MAX_PATH) BinaryPokeStr(bb, 0, path) ret = DllCall('shlwapi.dll', LONG:'PathStripToRootA', LPBINARY:bb) BinaryEodSet(bb, BinaryEodGet(bb)) ret = BinaryPeekStr(bb, 0, BinaryEodGet(bb)) BinaryFree(bb) Return ret #EndFunction strString1 = "\\SERVER\SHARE\FOLDER\FOLDER\FILE1.EXT" strString2 = "A:\FOLDER\FOLDER\FILE2.EXT" strString3 = "\FOLDER\FOLDER\FILE3.EXT" strString4 = "\FILE4.EXT" strString5 = "A:..\FILE5.EXT" strString6 = "..\FILE6.EXT" strString7 = "FILE7.EXT" ret1 = PathStripToRoot( strString1 ) ret2 = PathStripToRoot( strString2 ) ret3 = PathStripToRoot( strString3 ) ret4 = PathStripToRoot( strString4 ) ret5 = PathStripToRoot( strString5 ) ret6 = PathStripToRoot( strString6 ) ret7 = PathStripToRoot( strString7 ) Exit
Here is a WinBatch UDF udfPathRoot that mimics the PathStripToRoot functionality but needs no DllCall.
;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfPathRoot (strString) strPathRoot = "" arrPattern = Arrayize ("?:\" : @LF : "\\*\*\" : @LF : "\", @LF) For intI = 0 To 2 If 1 == StrIndexWild (strString, arrPattern [intI], 1) strPathRoot = StrSubWild (strString, arrPattern [intI], 1) If intI == 1 Then strPathRoot = StrSub (strPathRoot, 1, StrLen (strPathRoot) - 1) Break EndIf Next Return strPathRoot ;.......................................................................................................................................... ; This UDf udfPathRoot works like SHLWAPI.DLL "PathStripToRootA". ; ; Detlev Dalitz.20090630. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ; Test. strString1 = "\\SERVER\SHARE\FOLDER\FOLDER\FILE1.EXT" strString2 = "A:\FOLDER\FOLDER\FILE2.EXT" strString3 = "\FOLDER\FOLDER\FILE3.EXT" strString4 = "\FILE4.EXT" strString5 = "A:..\FILE5.EXT" strString6 = "..\FILE6.EXT" strString7 = "FILE7.EXT" strPathRoot1 = udfPathRoot (strString1) ; "\\SERVER\SHARE" strPathRoot2 = udfPathRoot (strString2) ; "A:\" strPathRoot3 = udfPathRoot (strString3) ; "\" strPathRoot4 = udfPathRoot (strString4) ; "\" strPathRoot5 = udfPathRoot (strString5) ; "" strPathRoot6 = udfPathRoot (strString6) ; "" strPathRoot7 = udfPathRoot (strString7) ; "" strFolderPath1 = StrSub (FilePath (strString1), StrLen (strPathRoot1) + 1, -1) ; "\FOLDER\FOLDER\" strFolderPath2 = StrSub (FilePath (strString2), StrLen (strPathRoot2) + 1, -1) ; "FOLDER\FOLDER\" strFolderPath3 = StrSub (FilePath (strString3), StrLen (strPathRoot3) + 1, -1) ; "FOLDER\FOLDER\" strFolderPath4 = StrSub (FilePath (strString4), StrLen (strPathRoot4) + 1, -1) ; "" strFolderPath5 = StrSub (FilePath (strString5), StrLen (strPathRoot5) + 1, -1) ; "A:..\" strFolderPath6 = StrSub (FilePath (strString6), StrLen (strPathRoot6) + 1, -1) ; "..\" strFolderPath7 = StrSub (FilePath (strString7), StrLen (strPathRoot7) + 1, -1) ; "" strFileBaseName1 = FileBaseName (strString1) ; "FILE1.EXT" strFileBaseName2 = FileBaseName (strString2) ; "FILE2.EXT" strFileBaseName3 = FileBaseName (strString3) ; "FILE3.EXT" strFileBaseName4 = FileBaseName (strString4) ; "FILE4.EXT" strFileBaseName5 = FileBaseName (strString5) ; "FILE5.EXT" strFileBaseName6 = FileBaseName (strString6) ; "FILE6.EXT" strFileBaseName7 = FileBaseName (strString7) ; "FILE7.EXT" Exit
Article ID: W18365
Filename: PathStripToRoot UDF.txt
File Created: 2009:07:01:11:34:28
Last Updated: 2009:07:01:11:34:28