I want to run mvn clean compile
in each directory in my Eclipse workspace containing a pom.xml
file.
I was able to run svn update
for each directory containing .svn
like this:
PS C:\workspace> Get-ChildItem -recurse -force |
where {$_.name -eq ".svn"} |
foreach {svn update $_.parent.FullName}
However, this gives the full path to svn
and runs from the current directory. The mvn clean compile
needs to be run inside the directory, afaik. Tried doing the following, but then I just get an error saying something can't be null. Seems to be the first cd
call it complains about. Do I just have some syntax wrong, or am I using foreach
wrong?
PS C:\workspace> Get-ChildItem -recurse |
where {$_.name -eq "pom.xml"} |
foreach { cd $_.parent.name; mvn clean compile; cd ..; }
If you want to list files and directories of a specific directory, utilize the “-Path” parameter in the “Get-ChildItem” command. This option will help PowerShell list all the child items of the specified directory. The “-Path” parameter is also utilized to set the paths of one or more locations of files.
The While statement in PowerShell is used to create a loop that runs a command or a set of commands if the condition evaluates to true. It checks the condition before executing the script block. As long as the condition is true, PowerShell will execute the script block until the condition results in false.
xcopy is the windows command. It works with both PowerShell and cmd as well because it is a system32 utility command.
Seems like $_.parent.FullName
property worked in the first case because I was filtering out only directories. In this case I filtered out files, so I got it working by using $_.DirectoryName
instead.
PS C:\workspace> Get-ChildItem -recurse |
where {$_.name -eq "pom.xml"} |
foreach { cd $_.DirectoryName; mvn clean compile; cd ..; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With