我期望从以下代码中获得的行为是:
循环并将每个文件复制到备份目标,只有它尚不存在.
if (!(Test-Path C:\Folder\Destination)) {
New-Item -ItemType Directory -Force -Path C:\Folder\Destination
}
$originalfiles = Get-ChildItem -Path "C:\Folder\Source"
$originalfiles
foreach ($file in $originalfiles) {
Write-Host
Write-Host File Name: -ForegroundColor DarkYellow
Write-Host $file.Name
Write-Host File Path: -ForegroundColor DarkYellow
Write-Host $file.FullName
$src = $file.FullName
$dest = "C:\Folder\Destination\$($file.Name)"
Copy-Item $src $dest
}
Run Code Online (Sandbox Code Playgroud)Copy-Item除非您指定-Force标志,否则我会认为cmdlet默认为不覆盖.这是我过去在遇到我想要覆盖的情况时会看到的行为.
此外,我认为它可能是foreach循环的介绍,但我尝试使用自己的复制命令,单个文件的硬编码路径,它仍然是相同的.
我应该重新启动IDE还是我忽略了一个错误?
我正在尝试学习如何使用MailKit库,但我正在努力检索附件.到目前为止,我的代码将打开一个邮箱,浏览每个邮件并存储数据,如发件人,主题,正文,日期等,但我不能处理附件.
我试图在github和其他网站上使用其他人解决方案,但我仍然不明白他们在代码中做了什么,当我接近获得解决方案时,它会导致更多错误,所以我会感到压力并删除所有代码.我并不是说看起来很懒,但如果有人能解释我是如何做到的,我会很高兴.我基本上是在为Web表单应用程序构建一个邮件客户端.
下面是我的代码,所以你可以看到我相当无能:)
// Open the Inbox folder
client.Inbox.Open(FolderAccess.ReadOnly, cancel.Token);
//get the full summary information to retrieve all details
var summary = client.Inbox.Fetch(0, -1, MessageSummaryItems.Full, cancel.Token);
foreach (var msg in summary)
{
//this code originally downloaded just the text from the body
var text = msg.Body as BodyPartText;
//but I tried altering it so that it will get attachments here also
var attachments = msg.Body as BodyPartBasic;
if (text == null)
{
var multipart = msg.Body as BodyPartMultipart;
if (multipart …Run Code Online (Sandbox Code Playgroud) 我试图更新DonorID列,设定为foreign key,在我的电子邮件表的值DonorID列primary key在我的Donor表.
该Donor表包含来自捐赠者的所有不同电子邮件地址,当它们进入我的电子邮件表时,将新地址添加到新行,并给出Donor一个ID.我想更新DonorID当前设置为的电子邮件表中的每个表0,以匹配DonorID我的Donor表中的相应表.
我可以查询表格以返回显示所有匹配的电子邮件地址的结果,但我无法计算更新我的电子邮件表格的逻辑,以反映DonorID与我的Donor表格中的该地址相关联的新内容.
这是我到目前为止的代码......
//join rows based on sender address
var join = from emai in db.Emails
from dono in db.Donors
where emai.Sender == dono.Email
select new{ Sender = emai.Sender, EID = emai.DonorID, DID = dono.DonorID };
gvJoin.DataSource = join;
gvJoin.DataBind();
// Query the database for the row to be …Run Code Online (Sandbox Code Playgroud)