PathLib

From NSIS Wiki
Jump to navigationJump to search

Description

A path library for providing LogicLib operators and transformation macros.

Minimum Requirements

  • NSIS 3.0 (Unicode)

Logical Operators

LogicLib operators for use with ${If}, ${IfNot}, ${ElseIf}, ${AndIf}, ${OrIf}, etc.

   ${If} ${Path.IsAbsolute} "C:\Windows\System32"
     DetailPrint '"C:\Windows\System32" is an absolute path'
   ${EndIf}
   
   ${If} ${Path.IsRelative} "docs\readme.txt"
     DetailPrint '"docs\readme.txt" is a relative path'
   ${EndIf}
   
   ${If} ${Path.IsUNC} "\\server\share\folder"
     DetailPrint '"\\server\share\folder" is a UNC path'
   ${EndIf}
   
   ${If} ${Path.IsValid} "C:\Program Files\My App\config.ini"
     DetailPrint '"C:\Program Files\My App\config.ini" is a valid path'
   ${EndIf}
   
   ${IfNot} ${Path.IsValid} "bad<path"
     DetailPrint '"bad<path" is not a valid path (contains <)'
   ${EndIf}
   
   ${If} ${Path.IsValidFileName} "report.pdf"
     DetailPrint '"report.pdf" is a valid filename'
   ${EndIf}
   
   ${IfNot} ${Path.IsValidFileName} "folder\file.txt"
     DetailPrint '"folder\file.txt" is not a valid filename (contains backslash)'
   ${EndIf}
   
   ${If} ${Path.IsFile} "$WINDIR\notepad.exe"
     DetailPrint '"$$WINDIR\notepad.exe" is a file'
   ${EndIf}
   
   ${If} ${Path.IsDirectory} "$WINDIR"
     DetailPrint '"$$WINDIR" is a directory'
   ${EndIf}
   
   ${If} ${Path.IsReadable} "$WINDIR\notepad.exe"
     DetailPrint '"$$WINDIR\notepad.exe" is readable'
   ${EndIf}
   
   ${If} ${Path.IsWritable} "$WINDIR\notepad.exe"
     DetailPrint '"$$WINDIR\notepad.exe" is writable'
   ${EndIf}
   
   ${IfNot} ${Path.IsHidden} "$WINDIR"
     DetailPrint '"$$WINDIR" is not hidden'
   ${EndIf}
   
   ${IfNot} ${Path.IsSymLink} "$WINDIR"
     DetailPrint '"$$WINDIR" is not a symlink'
   ${EndIf}

Transformations

Path transformation macros

   ${Path.Normalize} "C:\foo\bar\..\baz" $R0
   => Output: C:\foo\baz
   
   ${Path.Join} "C:\Users\Justin" "Documents\file.txt" $R0
   => Output: C:\Users\Jan\Documents\file.txt
   
   ${Path.Resolve} "relative\file.txt" $R0
   => Output: <current working directory>\relative\file.txt
   
   ${Path.Dirname} "C:\Users\Justin\report.pdf" $R0
   => Output: C:\Users\Justin
   
   ${Path.Extname} "C:\Users\Justin\report.pdf" $R0
   => Output: .pdf
   
   ${Path.Basename} "C:\Users\Justin\report.pdf" "" $R0
   => Output: report.pdf
   
   ${Path.Basename} "C:\Users\Justin\report.pdf" ".pdf" $R0
   => Output: report

Links