powershell - 检查文件夹中是否存在文件?
问题描述
我不知道该怎么做。我需要执行一个脚本。
该脚本需要监视创建的文件的文件夹。如果创建了文件,它将触发一系列功能。
但在此之前,脚本必须始终检查某个文件是否存在。因为否则脚本将不会执行。在执行任何其他操作之前,需要移动现有文件。
我尝试使用 filechanged 事件,但它会覆盖现有文件...
有没有办法做到这一点?
这是脚本的开头:
$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{
IncludeSubdirectories = $true # <-- set this according to your requirements
NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'
}
$onCreated = Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action {
$path = $Event.SourceEventArgs.FullPath
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Host "The file '$name' at '$path'was $changeType at $timeStamp" -Fore white
$lineas = (Get-Content $root\UNB\TMP\FACT_TEMPORAL.TXT | Measure-Object -Line).Lines
Write-Host "El archivo contiene $lineas lineas" -Fore white
if ($lineas -gt 3) {
Write-Host "El archivo contiene información" -Fore white
limpia
leeyedita
printpdf
borrar
renombra
} else {
Write-Host "El archivo NO contiene información" -Fore white
borrar
}
}
解决方案
推荐阅读
- php - Laravel 认证后重定向登录
- android - 无法调整 Firebase (Google) MLKit 人脸检测的准确性
- html - 如何通过 CSS 或使用任何插件在 WordPress 中滚动长子菜单
- numpy - 中值过滤器使 numpy 数组值无效
- jasper-reports - 使用基于 Web 的 Jasper 报告在 excel 文件中出现格式错误
- clojure - Clojure:过滤具有特定分机而不是文件夹文件夹的文件
- vue.js - JWT 不能在带有 Vuejs、Laravel 的实时服务器上工作
- compiler-errors - How to create thrust device_vector from opencv gpumat
- javascript - Angular - 高度和宽度的属性绑定不适用于图像
- svn - SVN 预提交检查