[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
不知行否
  1. $pathSource='D:\SCETC\dataXml'
  2. $pathCopy='D:\交易失败流水'
  3. $fileType='*603.xml'
  4. $matchString='"CardLocalFee":"0","CardLocalPayfee":"0"'
  5. if( -not (Test-Path -LiteralPath $pathSource)){cmd /c pause;exit}
  6. if( -not (Test-Path -LiteralPath $pathCopy)){cmd /c pause;exit}
  7. $fsw=new-object System.IO.FileSystemWatcher
  8. $fsw.path=$pathSource
  9. $fsw.filter=$fileType
  10. $theMain={
  11. if($args.count){
  12. $xmlFile=$args[0]
  13. }else{
  14. $xmlFile=Get-ChildItem -LiteralPath $pathSource -Filter $fileType |Sort {$_.LastWriteTime} |Select -Last 1 -Wait
  15. $xmlFile=$xmlFile.fullname
  16. }
  17. $xmlContent=[xml](Get-Content -LiteralPath $xmlFile -Encoding "UTF8")
  18. $r=$xmlContent.datas.data.attribute.value |foreach{$_ -match $matchString}
  19. if($true -in [object[]]$r){
  20. $thePath=$pathCopy+'\'+(Get-Date).ToString("yyyy-MM-dd")+'\'
  21. if( -not (Test-Path -LiteralPath $thePath)){$null=New-Item -Type Directory -Path $thepath}
  22. write-host "copy $xmlFile to $thePath" -ForegroundColor Green
  23. Copy-Item -LiteralPath $xmlFile -Destination $thePath
  24. }else{write-host "not match , do noting" -ForegroundColor Green}
  25. }
  26. "`n running... `n"
  27. $theMain.invoke()
  28. $whenCreateDo={
  29. $evArgs=$event.SourceEventArgs
  30. $createTime=$event.TimeGenerated
  31. $msg="{0} was {1} at {2}" -f $evArgs.FullPath,$evArgs.ChangeType,$createTime
  32. Write-Host $msg -ForegroundColor Yellow
  33. Start-Sleep -seconds 2
  34. $t=0
  35. while($t -lt 8){
  36. try{
  37. $s=Get-Content -LiteralPath ($evArgs.FullPath) -Encoding "UTF8"
  38. $t=128
  39. }catch{
  40. $t+=2
  41. write-host "open the newfile fail (maybe using) , retry $t seconds later" -ForegroundColor Red
  42. start-sleep -seconds $t
  43. }
  44. }
  45. $theMain.invoke($evArgs.FullPath)
  46. }
  47. Register-ObjectEvent -InputObject $fsw -EventName Created -Action $whenCreateDo -SourceIdentifier fileCreate
  48. if(!$fsw.enableraisingevents){$fsw.enableraisingevents=$true}
  49. "`n press CTRL+C to exit `n"
  50. try{
  51. Wait-Event -SourceIdentifier fileCreate
  52. }finally{
  53. $fsw.enableraisingevents=$false
  54. Unregister-Event -SourceIdentifier fileCreate
  55. $fsw.dispose()
  56. "`n done `n"
  57. cmd /c pause
  58. }
复制代码
1

评分人数

TOP

返回列表