[英]How can I retrieve recursive directory name w/ Powershell?
I am attempting to use Powershell to automate the builds of projects using a cli compiler/linker. 我试图使用Powershell使用cli编译器/链接器自动化项目的构建。 I want to place the script in the root directory of a project and have it check for all source files recursively and compile them, with the compiler output pointed at the same directory as the source files.
我想将脚本放在项目的根目录中,让它以递归方式检查所有源文件并编译它们,编译器输出指向与源文件相同的目录。 I would also like to collect a list of the *.c as a comma-delimited variable as input to the linker.
我还想收集一个* .c列表作为逗号分隔的变量作为链接器的输入。 This is the typical situation:
这是典型的情况:
//projects/build_script.ps
//projects/proj_a/ (contains a bunch of source files)
//projects/proj_b/ (contains a bunch of source files)
I wish to scan all the sub directories and compile the source for each *.c file. 我希望扫描所有子目录并编译每个* .c文件的源代码。 This is what I have so far:
这是我到目前为止:
$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;
I realize that $_.current-directory isn't a real member, and I likely have other problems with the syntax. 我意识到$ _。current-directory不是真正的成员,我可能还有其他语法问题。 I apologize for the vagueness of my question, I am more than willing to further explain what may seem unclear.
我为我的问题含糊不清道歉,我更愿意进一步解释一些看似不清楚的问题。
Forgive me if I don't understand your exact requirement. 如果我不明白你的确切要求,请原谅我。 Below is an example of recursively getting all files with the .txt extension, and then listing the file's name and the containing directory's name.
下面是递归获取扩展名为.txt的所有文件,然后列出文件名和包含目录名的示例。 To get this I access the DirectoryName property value on the FileInfo object.
为此,我访问FileInfo对象上的DirectoryName属性值。 See FileInfo documentation for more information.
有关更多信息,请参阅FileInfo文档。
$x = Get-ChildItem . -Recurse -Include "*.txt"
$x | ForEach-Object {Write-Host "FileName: $($_.Name) `nDirectory: $($_.DirectoryName)"}
To take a stab at your current code: 要抓住您当前的代码:
$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}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.