用反斜杠分割路径,用斜杠连接路径



我想在反斜杠拆分两条路径,并将它们与斜杠/连接起来。

但是我收到一个错误,指出我没有该文件夹的权限,但我有管理员权限。

$PathOne = C:exampleexample
$PathTwo = C:exampleexample
$PathOne
$PathOne $PathOne("")
(Get-Content $PathTwo) -Join ("/")
$$PathTwo = $NewPath
$$PathTwo -Split("")
(Get-Content $PathTwo) -Join ("/")

错误是用"/"连接。

完整的错误代码: + FullQualifiedErrorId : GetContentReaderUnauthorizedAccessError,Microsoft.PowerShell.Command.GetContentCommand

要将C:exampleexample转换为C:/example/example,您可以使用替换方法(博客),如下所示:

$NewPathOne = $PathOne.Replace('','/')

如果您尚未指定尝试将其视为获取内容命令的文件,则会发生此错误。您必须指定文件的路径:get-content c:\patch\textfile.text 或:$PathOne = "c:\patch\textfile.text" $PathTwo = "c:\patch2\textfile2.text"(例如,您可以选择路径)
如果要将分隔符"\"替换为"/",请尝试以下操作:

$PathOne = "C:path1" 
$PathTwo = "C:path2"  
$repl1 = Get-ChildItem $PathOne -Recurse -force   
$repl2 = Get-ChildItem $PathTwo -Recurse -force   
$repl1 | % {
$_.FullName.ToString().Replace("","/")
} 
$repl2| % {
$_.FullName.ToString().Replace("","/")
}

最新更新