forked from 18thCentury/CodeSys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverwrite.ps1
63 lines (60 loc) · 1.89 KB
/
overwrite.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 定义常量变量
$codesysExePath = "C:\Program Files\CODESYS 3.5.16.30\CODESYS\Common\CODESYS.exe"
$codesysProfile = "CODESYS V3.5 SP16 Patch 3"
$scriptPath = "$PSScriptRoot\overwrite.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
}
$pou_path = Read-Host "Enter the path of pou as the src of overwriting"
# 去掉输入字符串两侧的引号
$pou_path = $pou_path.Trim('"')
# 输入的必须是文件路径
if ($pou_path)
{
if (Test-Path $pou_path -PathType Container)
{
Write-Host "The path '$pou_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 $pou_path'"
# 启动 CODESYS 进程
# Start-Process -NoNewWindow -Wait -FilePath $codesysExePath -ArgumentList $arguments
}
Read-Host -Prompt "Press Enter to exit"