Converting the FileSystemObject's GetFileName Method

Definition: Given a full path, returns the file portion of the path. For example, passing the path C:\Scripts\Test.txt to GetFileName will return Test.txt.


In PowerShell, use the Split-Path cmdlet with the -leaf parameter:

Split-Path C:\scripts\test.txt -leaf

See conversions of other FileSystemObject methods and properties.
Return to the VBScript to Windows PowerShell home page