กำหนดสตริงพา ธ โดยพลการเมธอดคงต่างๆบนอ็อบเจ็กต์ System.IO.Path ให้ผลลัพธ์ดังต่อไปนี้
strTestPath = C: \ Users \ DAG \ Documents \ Articles_2018 \ NTFS_File_Times_in_CMD \ PathStringInfo.ps1
GetDirectoryName = C: \ Users \ DAG \ Documents \ Articles_2018 \ NTFS_File_Times_in_CMD
GetFileName = PathStringInfo.ps1
GetExtension = .ps1
GetFileNameWithoutExtension = PathStringInfo
ต่อไปนี้เป็นรหัสที่สร้างผลลัพธ์ข้างต้น
[console]::Writeline( "strTestPath = {0}{1}" ,
$strTestPath , [Environment]::NewLine );
[console]::Writeline( "GetDirectoryName = {0}" ,
[IO.Path]::GetDirectoryName( $strTestPath ) );
[console]::Writeline( "GetFileName = {0}" ,
[IO.Path]::GetFileName( $strTestPath ) );
[console]::Writeline( "GetExtension = {0}" ,
[IO.Path]::GetExtension( $strTestPath ) );
[console]::Writeline( "GetFileNameWithoutExtension = {0}" ,
[IO.Path]::GetFileNameWithoutExtension( $strTestPath ) );
การเขียนและทดสอบสคริปต์ที่สร้างขึ้นข้างต้นได้เปิดโปงความไม่ชอบมาพากลบางอย่างเกี่ยวกับความแตกต่างของ PowerShell จาก C #, C, C ++, ภาษาสคริปต์คำสั่งของ Windows NT และทุกอย่างอื่น ๆ ที่ฉันมีประสบการณ์