简体   繁体   English

如何检索具有Powershell的递归目录名?

[英]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.

相关问题 如何使用Powershell更改Active Directory中的显示名称? - How can I change the display name in Active Directory with powershell? Powershell-如何获得列出无子文件且仅列出前5个文件的目录? - Powershell - How can I get a directory listing w/o subfiles and only list top 5 files? 如何从 PowerShell 检索递归目录和文件列表,不包括某些文件和文件夹? - How to retrieve a recursive directory and file list from PowerShell excluding some files and folders? PowerShell 如何使用 FTP 删除目录? - PowerShell How can I delete a directory with FTP? 如何从Powershell中包含完全限定文件名的变量中获取目录名? - How can I get just the directory name from a variable that includes a fully qualified filename in Powershell? 如何使用PowerShell和C#检索每个.bak文件? - How can I retrieve every .bak file with PowerShell and C#? 如何使用PowerShell检索原始文件名 - How to retrieve the original file name using PowerShell powershell:如何获取dns格式的计算机名 - powershell: how to retrieve the computer name in dns format Powershell:在删除目录之前先获取该目录的名称 - Powershell: Grab the name of the directory before I delete it 如何将环境变量用作Powershell中目录位置的开始? - How can I use an Environmental Variable as a start of a directory location in powershell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM