forked from 18thCentury/CodeSys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule_detect.ps1
38 lines (35 loc) · 1.5 KB
/
module_detect.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 定义常量变量
$codesysExePath = "C:\Program Files\CODESYS 3.5.16.30\CODESYS\Common\CODESYS.exe"
$codesysProfile = "CODESYS V3.5 SP16 Patch 3"
$scriptPath = "$PSScriptRoot\module_detection.py"
$project_path = Read-Host "Enter the directory containing .project files"
# 去掉输入字符串两侧的引号
$project_path = $project_path.Trim('"')
# 如果输入的是文件路径,则获取其上级目录
if ( $project_path ) {
if (Test-Path $project_path) {
if (-not (Test-Path $project_path -PathType Container)) {
# 如果输入的是文件,获取上级目录
$project_path = Split-Path $project_path
}
if (-not (Test-Path $scriptPath)) {
Write-Host "The file '$scriptPath' not found ."
Exit
}
} else {
Write-Host "The path '$project_path' is not valid. Exiting script."
Exit
}
} else {
Exit
}
# 获取当前目录下的所有 .project 文件及其子目录中的 .project 文件
$projectFiles = Get-ChildItem -Recurse -Filter "*.project" -Path $project_path | Where-Object { $_.Name -notmatch "E107" }
Write-Output "$($projectFiles.Count) projects found. Please confirm ..."
if ($projectFiles.Count -gt 0){
# 构造要执行的 CMD 命令
$arguments = "--profile='$codesysProfile' --noUI --runscript='$scriptPath' --scriptargs:'$project_path'"
# 启动 CODESYS 进程
Start-Process -NoNewWindow -Wait -FilePath $codesysExePath -ArgumentList $arguments
}
Read-Host -Prompt "Press Enter to exit"