新人请教问题 关于函数参数的问题
powershell吧
全部回复
仅看楼主
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
脚本内容如上
请教诸位,为什么函数运行时参数内容为空。谢谢!
新人学习,盼回音。
2020年11月11日 05点11分 1
level 7
hi,兄弟,给你一份提问的智慧,按照它提问,节省大家时间。
提问应该按照标准格式,即:
------------------
1你要干嘛,说出你的目的:
2你怎么干的,说出你的动作:
3遇到了什么问题:
4贴上命令,参数,的源码!贴上源码!方便别人帮你改命令。方便别人在自己机子上重复你的命令。
命令,贴上源码:
错误信息,贴上图:
操作系统,版本是:
.net版本是:
powershell版本是:
不贴源码的提问,自己是坑自己的傻蛋。不贴源码的分享,那算不得分享!
------------------
源码简短点,10行以内,谢谢。
2020年11月12日 08点11分 2
1