How to get recursive w / Powershell directory name?

I am trying to use Powershell to automate building projects using the cli compiler / linker. I want to put the script in the root directory of the project and check recursively and compile all the source files, and the compiler output is listed in the same directory as the source files. I would also like to compile a * .c list as a comma-delimited variable as input to the linker. This is a 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 want to scan all the auxiliary directories and compile the source for each * .c file. 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 understand that $ _. current-directory is not a real member, and I probably have other syntax issues. I apologize for the vagueness of my question, I am more than ready to explain what may seem obscure.

+4
source share
1 answer

Forgive me if I do not understand your exact requirement. The following is an example of recursively retrieving all files with a .txt extension, and then listing the file name and directory name. To do this, I access the value of the DirectoryName property of the FileInfo object. See the FileInfo documentation for more information.

 $x = Get-ChildItem . -Recurse -Include "*.txt" $x | ForEach-Object {Write-Host "FileName: $($_.Name) `nDirectory: $($_.DirectoryName)"} 

To get hit on 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} 
+7
source

Source: https://habr.com/ru/post/1345984/


All Articles