我试图使用Power shell使用cli编译器/链接器自动化项目的构建.我想将脚本放在项目的根目录中,让它以递归方式检查所有源文件并编译它们,编译器输出指向与源文件相同的目录.我还想收集
//projects/build_script.ps //projects/proj_a/ (contains a bunch of source files) //projects/proj_b/ (contains a bunch of source files)
我希望扫描所有子目录并编译每个* .c文件的源代码.这是我到目前为止:
$compilerLocation = "C:\Program Files (x86)\HI-TECH Software\PICC-18\PRO\9.63\bin\picc18.exe"; $args = "--runtime=default,+clear,+init,-keep"; $Dir = get-childitem C:\projects -recurse $List = $Dir | where {$_.extension -eq ".c"} $List | $compilerLocation + "-pass" + $_ + $args + "-output=" + $_.current-directory;
我意识到$_.current-directory不是真正的成员,我可能还有其他语法问题.我为我的问题含糊不清道歉,我更愿意进一步解释一些看似不清楚的问题.
如果我不明白你的确切要求,请原谅我.下面是递归获取扩展名为.txt的所有文件,然后列出文件名和包含目录名的示例.为此,我访问FileInfo对象上的DirectoryName属性值.有关更多信息,请参见 FileInfo文档.$x = Get-ChildItem . -Recurse -Include "*.txt" $x | ForEach-Object {Write-Host "FileName: $($_.Name) `nDirectory: $($_.DirectoryName)"}
要抓住您当前的代码:
$compilerLocation = "C:\Program Files (x86)\HI-TECH Software\PICC-18\PRO\9.63\bin\picc18.exe"; $args = "--runtime=default,+clear,+init,-keep"; $List = Get-ChildItem C:\project -Recurse -Include *.c $List | ForEach-Object{#Call your commands for each fileinfo object}