1

我正在尝试编写一个脚本,该脚本将跟踪何时将某些内容复制到目录“A”,然后将其复制到我们拥有的用于将文件移动到专用网络的文件夹中。我将该目录称为“b”。在另一端,我有一个脚本,它将“b”中的这些文件复制到一个文件夹,该文件夹镜像公共网络上的另一个文件夹,文件夹“c”。我只想获取最近复制到文件夹“a”中的那些文件。问题是文件中没有跟踪复制日期的属性。所以我想我会使用一个文本文件来跟踪它。我在下面写了这个脚本,但它不起作用。我认为这是因为当我从文本文件中提取信息时它不再是一个对象?无论如何,您可以提供的任何帮助将不胜感激。

$binaries = "\\network\home\binaries" 
$owt = "\\server1\owt\binaries"

function Get-Directories ($path)
{
    $PathLength = $path.length
        Get-ChildItem $path -Recurse | % {
        Add-Member -InputObject $_ -MemberType NoteProperty -Name RelativePath -Value $_.FullName.substring($PathLength+1)
    $_
}
}
$A= [IO.File]::ReadAllText("\\network\home\binaries\log\log.txt")
$B= Get-Directories $binaries 

#$stream = [System.IO.StreamWriter] "\\network\home\binaries\log\log.txt" | %   {$stream.WriteLine($b)}
#$stream.close() 
Compare-Object $A $B -Property RelativePath, Name, Length |
Sort RelativePath, Name, Length -desc | % {
if ($file -ne $_.RelativePath) { $_ } } | 
Where-Object {$_.SideIndicator -eq "=>"} | 
ForEach-Object {
    $file = $_.RelativePath
    Echo F | xcopy "$binaries\$file" "$owt\$file" /S
}
$c= Get-Directories $binaries | % { $c >> "\\network\home\binaries\log\log.txt"}
4

2 回答 2

1

安排运行 robocopy 的 shell 脚本可能更容易。Robocopy 具有似乎更适合您的场景的各种便捷功能(镜像、带宽限制、错误重启等)。

账单

于 2013-02-28T15:25:48.457 回答
0

您可以使用FileSystemWatcher编写脚本,然后使用srvany将其作为服务启动。

于 2013-03-01T07:55:04.280 回答