Filesystem-Commands

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Filesystem-Commands >

Filesystem-Commands

GPP. - Get Path Part

Previous Top Next (GFT.)


MiniRobotLanguage (MRL)

 

GPP. Command

Get Path Part

 

NTFS-Direct

Intention

 

GPP. evaluates a file path string based on specified keywords and modifiers. It returns requested parts of the file name and/or path, optionally controlling formatting like casing and trailing slashes.

This command replaces the older GFT. command with a more readable and flexible syntax.

The functionality is strictly one of parsing alone. No attempt is made to find the file on disk.

This command is similar to GFT. yet it has a different syntax and options.

 

Syntax

 

 

GPP.PartTypes|$$InputPath[|$$OutputVar1[|$$OutputVar...]]

 

 

Parameter Explanation

 

PartTypes: A comma-separated string containing keywords that specify which parts to extract and optional modifiers. Keywords and modifiers are case-insensitive.

 

Modifiers:

·mcase: Applies MCase (Title Case) formatting to the $$InputPath *before* extracting parts. Affects the case of the results.

·trimtrail: Removes any trailing backslash (\) or space from $$InputPath *before* processing (e.g., "C:\folder \ " becomes "C:\folder").

·concat: Concatenates all requested part keyword results into a single string. This combined result is placed in $$OutputVar1 (if provided) or on the Top-Of-Stack (TOS) if no output variables are given.

·fixlongpath: Removes the `\\?\` prefix from $$InputPath if present *before* processing. Otherwise, `\\?\` might be treated as part of the root.

·forceslash: Ensures that the result of a path-like keyword (see Keywords list) ends with a trailing backslash (\). Adds one if missing. Cannot be used with noslash.

·noslash: Ensures that the result of a path-like keyword (see Keywords list) does *not* end with a trailing backslash (\). Removes any trailing backslashes. Cannot be used with forceslash.

 

Part Keywords: (Using c:\Folder\Sub\Filename.pdf as primary example)

·root: Root drive or share (e.g., "c:", "\\server\share\") -> "c:" [Path-like¹]

·fileext: Filename with extension (After Last Backslash - ALB) -> "Filename.pdf"

·pathonly: Full path without filename, guaranteed no trailing '\' -> "c:\Folder\Sub" [Path-like¹]

·ext: File extension *without* the leading dot -> "pdf"

·nameonly: Filename *without* path or extension -> "Filename"

·noroots: Path and filename *without* the root drive -> "Folder\Sub\Filename.pdf" [Path-like¹]

·pathnoext: Full path and filename *without* the extension -> "c:\Folder\Sub\Filename" [Path-like¹]

·fullpath: Path portion *including* the trailing backslash '\' (if applicable) -> "c:\Folder\Sub\" [Path-like¹]

·extdot: Extension *including* the leading dot -> ".pdf"

·nameext: Filename and extension, *without* the path -> "Filename.pdf"

·parent: The path of the parent directory, typically ending with '\' -> "c:\Folder\Sub\" (from example), "c:\" (from "c:\file.txt") [Path-like¹]

·driveletter: The drive letter *only*, without colon or slash -> "c" (Returns empty string for UNC paths or paths without drive letters)

¹Path-like keywords are affected by the forceslash and noslash modifiers.

 

$$InputPath: The file path string (or a variable containing it, e.g., $$ABC) which shall be split into parts. Must be given.

 

$$OutputVar1, $$OutputVar2 ... $$Xyz: (optional) Variables (format $$ followed by exactly three characters) to receive the extracted parts.

·If the concat modifier is NOT used: The result of the first part keyword requested in PartTypes goes into $$OutputVar1, the second into $$OutputVar2, and so on. If fewer output variables are provided than parts requested, the remaining results are placed on the Top-Of-Stack (TOS), with the last requested part being topmost.

·If the concat modifier IS used: Only $$OutputVar1 is used (if provided) to store the single concatenated string. If no output variable is specified, the concatenated result goes to TOS.

 

 

Comprehensive Example

 

The following example demonstrates many features of GPP.

VAR.$$FIL=C:\Program Files (x86)\my app\launcher.exe

VAR.$$FLD=D:\Data\Images\

VAR.$$LNP=\\?\UNC\Server\Share\document.txt

VAR.$$UNC=\\Server\Share\script.mrl

 

PRT.Input File: $$FIL

GPP.root,pathonly,nameonly,ext,driveletter|$$FIL|$$ROT|$$POF|$$NMO|$$EXT|$$DLT

PRT.Root=$$ROT

PRT.Path Only=$$POF

PRT.Name Only=$$NMO

PRT.Extension=$$EXT

PRT.Drive Letter=$$DLT

PRT.--------------------------------

 

GPP.parent|$$FIL|$$PAR

PRT.Parent=$$PAR

GPP.parent|C:\TEMP|$$PRT

PRT.Parent of C:\TEMP=$$PRT

PRT.--------------------------------

 

PRT.Input Folder: $$FLD

GPP.fullpath,noslash|$$FLD|$$PNS

PRT.Full Path No Slash=$$PNS

GPP.pathonly,forceslash|$$FLD|$$PFS

PRT.Path Only Force Slash=$$PFS

PRT.--------------------------------

 

PRT.Using mcase modifier on $$FIL

GPP.fullpath,nameext,mcase|$$FIL

POP.$$NEX

POP.$$FUP

PRT.MCase Full Path=$$FUP

PRT.MCase Name+Ext=$$NEX

PRT.--------------------------------

 

PRT.Using concat modifier

GPP.pathnoext,extdot,concat|$$FIL|$$CN1

PRT.Concatenated Path+Name+DotExt=$$CN1

PRT.--------------------------------

 

PRT.Using fixlongpath modifier

PRT.Input Long Path: $$LNP

GPP.fixlongpath,root|$$LNP|$$FXR

PRT.Fixed Root=$$FXR

PRT.--------------------------------

 

PRT.Using trimtrail modifier

VAR.$$TT1=C:\Test\Folder\ 

GPP.trimtrail,pathonly|$$TT1|$$TRP

PRT.Trimmed Trail Path Only=$$TRP

PRT.--------------------------------

 

PRT.UNC Path Example

PRT.Input UNC: $$UNC

GPP.root,nameonly,extdot|$$UNC|$$URT|$$UNM|$$UEX

PRT.UNC Root=$$URT

PRT.UNC Name Only=$$UNM

PRT.UNC Ext Dot=$$UEX

GPP.driveletter|$$UNC|$$UDL

PRT.UNC Drive Letter=$$UDL

PRT.--------------------------------

 

MBX.GPP Demo Complete!

END.

 

 

Remarks

 

·Keywords and Modifiers in PartTypes are case-insensitive.

·This command supports NTFS-direct.

·The order of part keywords in PartTypes determines the output order when not using concat and when sending results to output variables or the stack (TOS).

·The forceslash and noslash modifiers only affect path-like results (see keyword list). They are mutually exclusive.

·The parent keyword typically returns the parent path including a trailing slash (unless it's the root drive like "C:\" or modified by noslash). For a path without a directory component (e.g., "file.txt"), it returns an empty string.

 

Limitations:

 

·The maximum number of distinct output parts (when not using concat) is limited by the internal parameter splitting mechanism (typically around 18 separate output variables can be specified).

 

 

See also:

 

  1.5.2 Working with Text-Strings

  GFT. - Get-File-Token (Older command)

  ALB - After last Backslash (Concept)

  BLB - Before last Backslash (Concept)

  GSS. - GetSplitString

  GFS. - Get-Filtered-String