最近需要同步代码修改给其他团队合作,通过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]) 跳过"
}
}