我正在尝试编写一个脚本,用于跟踪何时复制到目录“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"}