【问题标题】:Compare destination files with source files delete only the copied files. New files being added every 5 minutes in source directory/subfolders将目标文件与源文件进行比较,仅删除复制的文件。每 5 分钟在源目录/子文件夹中添加新文件
【发布时间】:2016-11-15 05:29:50
【问题描述】:

我是 powershell 新手 我在powershell中有以下代码 文件正在从 AS400 服务器移动到 \ServerZoro\AS400 文件夹和 #200 子文件夹。

AS400 管理员表示他的团队正在工作

从 Zoro 服务器到 Sharepoint 2013 服务器的文件被复制到 #200 个个人文件夹中(它们是销售报告)

Sharepoint 代码运行良好,此处未包含。

问题是: as400 服务器不断将新文件推送到 \Serverzoro\AS400 文件夹和#subfolders(当脚本运行时)

我需要一些 powershell 代码来: 1) 在仅删除复制的#files 之前将目标文件与源文件 (?) 进行比较,以便在添加新文件时不会删除它们。

脚本每 15 分钟运行一次,我现在设置为 30 分钟。

Sharepoint 方面完美运行,只是上面的代码我遇到了问题。随机一个销售人员遗漏了一份报告

一周有 4 人漏掉 4 份报告。

下周有 1 人漏报

今天有 4 名销售人员缺少 4 份报告。

帮助赞赏!!!

$SourceReportDump = "\\ServerZoro\as400"
# Drive X below goes into the sp2013 server perfectly
$TargetReportDump = "x:"

$IncludeFiles = ("*.pdf","*.xls","*.xlsx","*.txt")

$WebUrl = "http://sp2013.sitename.com/sites/reports"

$DocLibraryName = "AS400Reports"

$DocLibraryUrlName = "AS400Reports"

#Move reports into Sharepoint

$CopyReports = Get-ChildItem -Path $SourceReportDump | Copy-Item            -Destination $TargetReportDump -Recurse  

$MoveReports = Get-ChildItem -Path $SourceReportDump -Recurse -include            $IncludeFiles | sort datemodified -Descending | select -Skip 65 | Remove-Item

【问题讨论】:

  • 请不要大喊大叫。
  • select -Skip 65 跳出来。硬编码值迟早会产生问题。为什么是65?为什么你认为它总是 65?
  • 对不起,数字 65 只是随机的——并不是要“喊”;新发帖。有没有办法“循环”每个报告、移动报告并在删除原始报告之前检查原始报告?

标签: powershell


【解决方案1】:

使用移动命令而不是复制+删除(如果您的复制有效而您的删除无效?)

就这样

$SourceReportDump = '\\ServerZoro\as400'
$TargetReportDump = 'x:'
$IncludeFiles = ("*.pdf","*.xls","*.xlsx","*.txt")

Get-ChildItem -Path $SourceReportDump -file -Recurse -include $IncludeFiles | %{$newpath=$_.DirectoryName -Replace [regex]::escape($SourceReportDump),$TargetReportDump;  if ($newpath -ne $TargetReportDump) {new-item -ItemType Directory  -path  $newpath -Force} ; move-item $_.FullName "$newpath\$($_.Name)" -Force  }

【讨论】:

  • 问题是 AS400 不断地将报告转储到源报告转储位置。当 powershell 脚本运行时,有时会丢失报告被复制并被删除。我需要一个“针对每个报告循环”的代码行来检查源文件并移动它……而不是删除脚本运行时正在填充的新报告……谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-07
  • 1970-01-01
相关资源
最近更新 更多