我正在使用批处理脚本来获取特定项目的最新版本。该脚本仅运行tf.exe并获取某些Binaries的最新版本。一切正常,但我想将下载文件的属性更改为可写的(默认情况下,这些文件为只读)。为此,我想确定文件的本地路径并从批处理中使用attrib命令。

tf.exe工作文件夹[工作空间]以某种列表的形式向我显示了本地路径,但是如果只显示我想要的内容,这样会更容易,因此可以使用提示。到现在为止,它看起来像这样:

tf.exe workfold [Workspace]

=======================================

Arbeitsbereich: XYZ-xxxxxx (Username)

Auflistung: TFS-URL

[Workspace]:  C:\xxx\TFS\xxx

是否可以仅确定TFS工作区的本地路径映射,以便我可以对attrib-command使用提示而不进行解析?

最佳答案

接下来的(粗鲁!!)概念呢?

function Get-TfsWorkfold([string]$TfsCollection, [string]$TfsWorkspace)
{
    $TfExePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 10.0\Common7\IDE\TF.exe"
    Write-Output "Getting workfold for '$TfsCollection'->'$TfsWorkspace'..."
    Push-Location $LocalPath
    & "$TfExePath" workfold /collection:$TfsCollection /workspace:$TfsWorkspace
}

function Handle-Path()
{
    param([Parameter(ValueFromPipeline=$true,Position=0)] [string] $line)
    $startIndex = $line.IndexOf(': ') + 2;
    $correctedLine = $line.subString($startIndex, $line.length - $startIndex - 1);
    Write-Output $correctedLine;
    Get-ChildItem $correctedLine
}

Get-TfsWorkfold "{serverAndcollection}"  "{workspace}" > c:\temp\test.txt
Select-String c:\temp\test.txt -pattern:': ' | Select-Object Line | Handle-Path

Handle-Path的最后一行是示例,您可以根据需要重新编写。它是PowerShell,但是应该可以根据需要运行。

替换{serverAndcollection}和{workspace}。

08-27 01:06