小编For*_*s1k的帖子

PowerShell 核心。相对路径问题

电源外壳:

$file = "text.txt"
Test-Path $file            
# True
 
Get-Location
# C:\Users\Fors1k

[IO.File]::OpenRead($file) 
# FileStream
 
[IO.FileInfo]::new($file)  
# Mode                 LastWriteTime         Length Name                         
# ----                 -------------         ------ ----                         
# -a----        05.03.2021     18:12              7 text.txt  
                      
gc $file                   
# test123
Run Code Online (Sandbox Code Playgroud)

一切都好。

PowerShell 核心:

$file = "text.txt"
Test-Path $file            
# True
 
Get-Location
# C:\Users\Fors1k

[IO.File]::OpenRead($file) 
# Exception calling "OpenRead" with "1" argument(s): "Could not find file 'C:\Windows\system32\text.txt'."
 
[IO.FileInfo]::new($file)  
# Mode                 LastWriteTime         Length Name                         
# ----                 -------------         ------ ----
# larhs          01.01.1601     3:00  
                      
gc $file                   
# test123 …
Run Code Online (Sandbox Code Playgroud)

.net powershell .net-core powershell-core

1
推荐指数
1
解决办法
1583
查看次数

标签 统计

.net ×1

.net-core ×1

powershell ×1

powershell-core ×1