1- # ##############################################################################
1+ # ##############################################################################
22<#
33. SYNOPSIS
44Expands any given file reference to a full pathname.
@@ -21,11 +21,11 @@ Expand-Path -FilePath ".\myfile.txt" -CreateFile
2121
2222. EXAMPLE
2323ep ~\documents\test.txt -CreateFile
24- ############################################################################## #>
24+ #>
2525function Expand-Path {
2626
2727 [CmdletBinding ()]
28- [Alias (" ep " )]
28+ [Alias (' ep ' )]
2929
3030 param (
3131 # #######################################################################
@@ -34,44 +34,44 @@ function Expand-Path {
3434 Position = 0 ,
3535 ValueFromPipeline = $true ,
3636 ValueFromPipelineByPropertyName = $true ,
37- HelpMessage = " Path to expand"
37+ HelpMessage = ' Path to expand'
3838 )]
3939 [ValidateNotNullOrEmpty ()]
4040 [string ] $FilePath ,
4141 # #######################################################################
4242 [Parameter (
4343 Mandatory = $false ,
44- HelpMessage = " Will create directory if it does not exist"
44+ HelpMessage = ' Will create directory if it does not exist'
4545 )]
4646 [switch ] $CreateDirectory ,
4747 # #######################################################################
4848 [Parameter (
4949 Mandatory = $false ,
50- HelpMessage = " Will create an empty file if it does not exist"
50+ HelpMessage = ' Will create an empty file if it does not exist'
5151 )]
5252 [switch ] $CreateFile ,
5353 # #######################################################################
5454 [Parameter (
5555 Mandatory = $false ,
56- HelpMessage = " Will delete the file if it already exists"
56+ HelpMessage = ' Will delete the file if it already exists'
5757 )]
5858 [switch ] $DeleteExistingFile ,
5959 # #######################################################################
6060 [Parameter (
6161 Mandatory = $false ,
62- HelpMessage = " Will force the use of a specific drive"
62+ HelpMessage = ' Will force the use of a specific drive'
6363 )]
6464 [char ] $ForceDrive = ' *' ,
6565 # #######################################################################
6666 [Parameter (
6767 Mandatory = $false ,
68- HelpMessage = " Will throw if file does not exist"
68+ HelpMessage = ' Will throw if file does not exist'
6969 )]
7070 [switch ] $FileMustExist ,
7171 # #######################################################################
7272 [Parameter (
7373 Mandatory = $false ,
74- HelpMessage = " Will throw if directory does not exist"
74+ HelpMessage = ' Will throw if directory does not exist'
7575 )]
7676 [switch ] $DirectoryMustExist
7777 # #######################################################################
@@ -80,8 +80,8 @@ function Expand-Path {
8080 begin {
8181
8282 # normalize path separators and remove double separators
83- [string ] $normalizedPath = $FilePath.Trim ().Replace(" \ " , [IO.Path ]::DirectorySeparatorChar).
84- Replace(" / " , [IO.Path ]::DirectorySeparatorChar);
83+ [string ] $normalizedPath = $FilePath.Trim ().Replace(' \ ' , [IO.Path ]::DirectorySeparatorChar).
84+ Replace(' / ' , [IO.Path ]::DirectorySeparatorChar);
8585
8686 if ($normalizedPath.StartsWith ([IO.Path ]::DirectorySeparatorChar + [IO.Path ]::DirectorySeparatorChar)) {
8787
@@ -92,10 +92,10 @@ function Expand-Path {
9292 )
9393
9494 if (($ForceDrive -ne ' *' ) -and
95- (" ABCDEFGHIJKLMNOPQRSTUVWXYZ" .IndexOf(($ForceDrive -as [string ]).ToUpperInvariant()) -ge 0 )) {
95+ (' ABCDEFGHIJKLMNOPQRSTUVWXYZ' .IndexOf(($ForceDrive -as [string ]).ToUpperInvariant()) -ge 0 )) {
9696
9797 $i = $normalizedPath.IndexOf ([IO.Path ]::DirectorySeparatorChar, 2 );
98- $normalizedPath = $ForceDrive + " : " + (
98+ $normalizedPath = $ForceDrive + ' : ' + (
9999
100100 $i -lt 0 ? ([IO.Path ]::DirectorySeparatorChar) : $normalizedPath.Substring ($i )
101101 )
@@ -116,18 +116,18 @@ function Expand-Path {
116116 }
117117
118118
119- process {
119+ process {
120120
121121 # expand home directory if path starts with ~
122- if ($normalizedPath.StartsWith (" ~ " )) {
122+ if ($normalizedPath.StartsWith (' ~ ' )) {
123123
124124 if (($ForceDrive -ne ' *' ) -and
125- (" ABCDEFGHIJKLMNOPQRSTUVWXYZ" .IndexOf(($ForceDrive -as [string ]).ToUpperInvariant()) -ge 0 )) {
125+ (' ABCDEFGHIJKLMNOPQRSTUVWXYZ' .IndexOf(($ForceDrive -as [string ]).ToUpperInvariant()) -ge 0 )) {
126126
127127 $i = $normalizedPath.IndexOf ([IO.Path ]::DirectorySeparatorChar, 1 );
128- $normalizedPath = $ForceDrive + " : " + (
128+ $normalizedPath = $ForceDrive + ' : ' + (
129129
130- $i -lt 0 ? [IO.Path ]::DirectorySeparatorChar + " ** " + [IO.Path ]::DirectorySeparatorChar : (" \**" + $normalizedPath.Substring ($i ))
130+ $i -lt 0 ? [IO.Path ]::DirectorySeparatorChar + ' ** ' + [IO.Path ]::DirectorySeparatorChar : (' \**' + $normalizedPath.Substring ($i ))
131131 )
132132 }
133133 else {
@@ -138,12 +138,12 @@ process {
138138 }
139139
140140 if ((($normalizedPath.Length -gt 1 ) -and
141- ($normalizedPath.Substring (1 , 1 ) -eq " : " ))) {
141+ ($normalizedPath.Substring (1 , 1 ) -eq ' : ' ))) {
142142
143143 if (($ForceDrive -ne ' *' ) -and
144- (" ABCDEFGHIJKLMNOPQRSTUVWXYZ" .IndexOf(($ForceDrive -as [string ]).ToUpperInvariant()) -ge 0 )) {
144+ (' ABCDEFGHIJKLMNOPQRSTUVWXYZ' .IndexOf(($ForceDrive -as [string ]).ToUpperInvariant()) -ge 0 )) {
145145 $i = $normalizedPath.IndexOf ([IO.Path ]::DirectorySeparatorChar);
146- $normalizedPath = $ForceDrive + " : " + [IO.Path ]::DirectorySeparatorChar + (($i -eq -1 -and $normalizedPath.Length -gt 2 ) -or $i -eq 2 ? " ** " + [IO.Path ]::DirectorySeparatorChar : " " ) + $normalizedPath.Substring (2 )
146+ $normalizedPath = $ForceDrive + ' : ' + [IO.Path ]::DirectorySeparatorChar + (($i -eq -1 -and $normalizedPath.Length -gt 2 ) -or $i -eq 2 ? ' ** ' + [IO.Path ]::DirectorySeparatorChar : ' ' ) + $normalizedPath.Substring (2 )
147147 }
148148 else {
149149
@@ -168,24 +168,24 @@ process {
168168 $normalizedPath = [System.IO.Path ]::GetFullPath($normalizedPath )
169169 }
170170 catch {
171- Microsoft.PowerShell.Utility\Write-Verbose " Failed to normalize path, keeping original"
171+ Microsoft.PowerShell.Utility\Write-Verbose ' Failed to normalize path, keeping original'
172172 }
173173 }
174174 else {
175175
176176 if (($ForceDrive -ne ' *' ) -and
177- (" ABCDEFGHIJKLMNOPQRSTUVWXYZ" .IndexOf(($ForceDrive -as [string ]).ToUpperInvariant()) -ge 0 )) {
177+ (' ABCDEFGHIJKLMNOPQRSTUVWXYZ' .IndexOf(($ForceDrive -as [string ]).ToUpperInvariant()) -ge 0 )) {
178178
179- if ($normalizedPath.Length -lt 2 -or $normalizedPath.Substring (1 , 1 ) -ne " : " ) {
179+ if ($normalizedPath.Length -lt 2 -or $normalizedPath.Substring (1 , 1 ) -ne ' : ' ) {
180180
181- $newPath = $ForceDrive + " : " + [IO.Path ]::DirectorySeparatorChar;
181+ $newPath = $ForceDrive + ' : ' + [IO.Path ]::DirectorySeparatorChar;
182182
183- while ($normalizedPath.StartsWith (" . " )) {
183+ while ($normalizedPath.StartsWith (' . ' )) {
184184
185185 $i = $normalizedPath.IndexOf ([IO.Path ]::DirectorySeparatorChar);
186186 if ($i -lt 0 ) {
187187
188- $normalizedPath = " "
188+ $normalizedPath = ' '
189189 }
190190 else {
191191
@@ -199,7 +199,7 @@ process {
199199 }
200200 else {
201201
202- $newPath += " ** " + [IO.Path ]::DirectorySeparatorChar + $normalizedPath
202+ $newPath += ' ** ' + [IO.Path ]::DirectorySeparatorChar + $normalizedPath
203203 }
204204
205205 $normalizedPath = $newPath
@@ -264,7 +264,7 @@ process {
264264
265265 # verify path doesn't point to existing directory
266266 if ([IO.Directory ]::Exists($normalizedPath )) {
267- throw " Cannot create file: Path refers to an existing directory"
267+ throw ' Cannot create file: Path refers to an existing directory'
268268 }
269269
270270 if (-not (GenXdev.FileSystem\Remove-ItemWithFallback - Path $normalizedPath )) {
@@ -287,13 +287,13 @@ process {
287287
288288 # verify path doesn't point to existing directory
289289 if ([IO.Directory ]::Exists($normalizedPath )) {
290- throw " Cannot create file: Path refers to an existing directory"
290+ throw ' Cannot create file: Path refers to an existing directory'
291291 }
292292
293293
294294 # create empty file if it doesn't exist
295295 if (-not [IO.File ]::Exists($normalizedPath )) {
296- $null = [IO.File ]::WriteAllText($normalizedPath , " " )
296+ $null = [IO.File ]::WriteAllText($normalizedPath , ' ' )
297297 Microsoft.PowerShell.Utility\Write-Verbose " Created empty file: $normalizedPath "
298298 }
299299 }
@@ -303,5 +303,4 @@ process {
303303
304304 end {
305305 }
306- }
307- # ##############################################################################
306+ }
0 commit comments