回复 4# LJY4.0 - #@&cls&powershell "type %~s0|out-string|iex"&pause&exit
- $path='c:\temp'
- $global:a=@{}
- [Environment]::GetLogicalDrives()|%{
- $fsw=New-Object IO.FileSystemWatcher $_ -Property @{IncludeSubdirectories=1;EnableRaisingEvents=1}
- 'Created','Deleted'|%{Register-ObjectEvent $fsw -EventName $_ -Action {$a[$event.EventIdentifier]=$event}}
- }
- while(1){
- Wait-Event -Timeout 1
- $a.clone().keys|?{$a[$_].SourceEventArgs.FullPath -match [regex]::Escape($path) -and $a[$_].SourceEventArgs.ChangeType -eq 'Created'}|%{
- $d=$a[$_].SourceEventArgs.FullPath
- if($d -match '[^\\]*$'){
- $a.clone().keys|?{
- $a[$_].SourceEventArgs.ChangeType -eq 'Deleted' -and
- $a[$_].SourceEventArgs.FullPath -match [regex]::Escape($matches[0]) -and
- $a[$_].SourceEventArgs.FullPath -notmatch [regex]::Escape($path)
- }|%{
- $s=$a[$_].SourceEventArgs.FullPath
- $a.remove($_)
- }
- if($s -ne $null -and $d -ne $null){
- "$s -> $d"
- $yn=read-host 'Y/N'
- if($yn -eq 'Y'){move $d $s}elseif($yn -eq 'N'){del $d}
- }
- $a.remove($_)
- }
- }
- rv d,s -ErrorAction SilentlyContinue
- }
复制代码
|