PowerShell提取TFS更新记录中的文件列表

最近需要同步代码修改给其他团队合作,通过TFS提取了文件列表,但一个个文件找出来复制很麻烦,于是写个程序来搞吧。
原本想用C#的,但好像太大了,选PowerShell好像不错。
第一次写PowerShell,一路查百度,总算跑出来了。

更新文件列表格式如下 .\updateSrcList_2017-03-15.txt

$/Source/新版程序源代码/Management/ServiceHost/App.config 编辑
$/Source/新版程序源代码/Management/ServiceHost/ConsoleRunner.cs   添加
$/Source/新版程序源代码/Management/ServiceHost/ServiceHost.csproj 编辑
$/Source/新版程序源代码/Management/ServiceHost/Program.cs 编辑
$/Source/新版程序源代码/Management/LogisticsPlatform.Service/Services/OceanFreight
$/Source/新版程序源代码/Management/LogisticsPlatform.Service/Services/OceanFreight/DynamicEtaService.cs   编辑
$/Source/新版程序源代码/Management/LogisticsPlatform.ServiceDefine/DataObjects/OceanFreight
$/Source/新版程序源代码/Management/LogisticsPlatform.ServiceDefine/DataObjects/OceanFreight/ShipETA.cs    编辑
$/Source/新版程序源代码/Management/LogisticsPlatform.DataService/LogisticsPlatform.DataService.csproj 编辑

脚本文件如下 .\buildPublishSrc.ps1

$list_file = ".\updateSrcList_2017-03-15.txt"
$output_path = "E:\src-temp\t1"
$local_path="D:\Source\新版程序源代码"
$tfs_base_path="`$/Source/新版程序源代码"
$tfs_base_path_head_len = $tfs_base_path.Length

Write-Host "list_file: $list_file"
Write-Host "output_path: $output_path"

$files = Get-Content $list_file 
For($i=0;$i -lt $files.Count; $i++)
{
    $index = $files[$i].IndexOf("`t");
    if ($index -gt 0)
    {
        $src = $files[$i].SubString($tfs_base_path_head_len, $index-$tfs_base_path_head_len).Replace("/","\")
    Write-Host "file $i : $local_path$src"

    #创建目录
    $desc_path = [System.IO.Path]::GetDirectoryName($src)
    #Write-Host $output_path$desc_path$desc
    new-item -path $output_path  -name $desc_path -type directory -force

    #复制文件
    Copy-Item $local_path$src $output_path$desc_path$desc
  }else{
    #目录而已,打印一下就跳过
    Write-Host "file $i : $($files[$i]) 跳过"
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值