From 53a6f925e9e85296b9b8b38183bb764761db05dd Mon Sep 17 00:00:00 2001 From: Guy Leech Date: Tue, 20 Aug 2024 17:50:08 +0100 Subject: [PATCH] Added quoting of path if has spaces --- totsclient.ps1 | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/totsclient.ps1 b/totsclient.ps1 index 94b94ac..88a44b3 100644 --- a/totsclient.ps1 +++ b/totsclient.ps1 @@ -36,7 +36,7 @@ Function totsclient( [string]$path , [switch]$noClipboard , [string]$prefix = 't else { ## deal with absolute path which may or may not be quoted at start with " - [string]$tsclientPath = $path -replace '^(?"?)(?\w):' , "`${quote}\\$prefix\`${drive}$suffix" + [string]$tsclientPath = $path.Trim() -replace '^(?"?)(?\w):' , "`${quote}\\$prefix\`${drive}$suffix" if( $tsclientPath -ieq $path ) { Write-Warning -Message "No change made to path $path" @@ -47,7 +47,15 @@ Function totsclient( [string]$path , [switch]$noClipboard , [string]$prefix = 't } else { - "`"$tsclientPath`"" | Set-Clipboard + ## quote it if contains spaces and not already quoted + if( $tsclientPath -match '^[^"].*\s+' ) + { + "`"$tsclientPath`"" | Set-Clipboard + } + else ## no need for quoting + { + $tsclientPath | Set-Clipboard + } } } -} \ No newline at end of file +}