level 1



假设目录结构如图。Function Find-Different
{
param ($FilesOfExcludeSource,$FilesOfDestination,$FilePath)
$FilesofExcludeSource | Write-Output
$FilesOfDestination | Write-Output
$FilePath | Write-Output
foreach ( $FileOfExcludeSource in $FilesOExcludefSource)
{
$FileOfExcludeSource | Write-Output
foreach ($FileOfDestination in $FilesOfDestination)
{
$FileOfDestination | Write-Output
$identical = 0
$identical | Write-Output
$FileOfExcludeSource.Name | Write-Output
$FileOfDestination.Name | Write-Output
if ($FileOfExcludeSource.Name -eq $FileOfDestination.Name)
{
$identical = 1
$identical | Write-Output
break
}
}
$identical | Write-Output
if ($identical -eq 0)
{
Write-Output $FileOfExcludeSource.Name | Out-File -FilePath $FilePath -Append
}
}
}
Function Skip-Files
{
param ($ExcludePaths,$FilesOfAllSource)
$ExcludePaths | Write-Output
$FilesOfAllSource | Write-Output
foreach ( $FileOfAllSource in $FilesOfAllSource)
{
$FileOfAllSource | Write-Output
foreach ($ExcludePath in $ExcludePaths)
{
$ExcludePath | Write-Output
$identical = 0
$FileOfAllSource.Fullname | Write-Output
if ($FileOfAllSource.Fullname -contains $ExcludePath)
{
$identical = 1
$identical | Write-Output
break
}
}
if ($identical -eq 0)
{
$identical | Write-Output
$identical | Write-Output
$FileOfAllSource
}
}
}
$SourcePath = 'D:\s'
$SourcePath | Write-Output
$DestinationPath = 'D:\d'
$DestinationPath | Write-Output
$ExcludePaths = 'D:\s\d'
$ExcludePaths | Write-Output
$FilePath = 'D:\Users\Owner\Downloads\Result.txt'
$FilePath | Write-Output
$FilesOfDestination = Get-ChildItem -Path $DestinationPath -Recurse -File
$FilesOfDestination | Write-Output
$FilesOfAllSource = Get-Childitem -Path $SourcePath -Recurse -File
$FilesOfAllSource | Write-Output
$FilesofExcludeSource = Skip-Files -ExcludePaths $ExcludePaths -FilesOfAllSource $FilesOfAllSource
$FilesofExcludeSource | Write-Output
Find-Different -FilesOfExcludeSource $FilesOfExcludeSource -FilesOfDestination $FilesOfDestination -FilePath $FilePath
脚本内容如上
请教诸位,为什么函数运行时参数内容为空。谢谢!
新人学习,盼回音。