Powershell: resolve path that might not exist?

前端 未结 13 2469
再見小時候
再見小時候 2020-12-02 13:05

I\'m trying to process a list of files that may or may not be up to date and may or may not yet exist. In doing so, I need to resolve the full path of an item, even though

13条回答
  •  独厮守ぢ
    2020-12-02 13:38

    function Get-FullName()
    {
        [CmdletBinding()]
        Param(
            [Parameter(ValueFromPipeline = $True)] [object[]] $Path
        )
        Begin{
            $Path = @($Path);
        }
        Process{
            foreach($p in $Path)
            {
                if($p -eq $null -or $p -match '^\s*$'){$p = [IO.Path]::GetFullPath(".");}
                elseif($p -is [System.IO.FileInfo]){$p = $p.FullName;}
                else{$p = [IO.Path]::GetFullPath($p);}
                $p;
            }
        }
    }
    

提交回复
热议问题