0
我需要遍历在一个目录中找到的.vcf文件,以使用powershell将它们合并成一个.vcf文件。我希望N:
的值是文件名。这是我的,它不工作。请帮忙。使用PowerShell循环使用VCF文件生成一个VCF
$fileDirectory = "c:\Contacts";
$parse_results = New-Object System.Collections.ArrayList;
$vcard = ""
foreach($file in Get-ChildItem $fileDirectory)
{
$contacts = ConvertFrom-Csv (Get-Content $file.FullName).Replace(';',',')
foreach ($contact in $contacts) {
$vcard = $vcard + "BEGIN:VCARD" + "`r`n"
$vcard = $vcard + "VERSION:3.0" + "`r`n"
$vcard = $vcard + "N:" + $file.Basename + ";" + "" + "`r`n"
$vcard = $vcard + "FN:" + "" + " " + "" + "`r`n"
$vcard = $vcard + "TEL:" + $contact."general phone" + "`r`n"
$vcard = $vcard + "EMAIL:" + $contact."general email" + "`r`n"
$vcard = $vcard + "END:VCARD" + "`r`n"
}
$vcard | Add-Content ($File.Basename + ".vcf")
}
谢谢。
更新:我得到了它使用此代码工作(代码对于调试变得简单)
$files = Get-ChildItem "C:\Contacts\"
for ($i=0; $i -lt $files.Count; $i++) {
$string = ""
$string = Get-Content $files[$i].FullName | Out-String
$newName = "N:" + $files[$i].BaseName
$string -replace '(?m)^N:{1}\W.*$', $newName
}
这就产生了一个文件,所有VCF信息相结合。 我遇到的困难是因为我不知道.vcf文件如何工作。很简单。
这是什么代码产生的工作?任何错误消息?错误的文件名?请将结果复制并粘贴到问题中。 – lit
如果您自己解决问题,请发表解答 –