1

I am trying to move some files to a relative subfolder recursivly.

I want to use the get-location command and combine it with a string ("\foo_1"), while using it as a parameter.

So get-location should result in "D:\foo_2" so that the result is "D:\foo_2\foo_1"

All while being a parameter of a separate command:

Get-ChildItem -Path ".\*.wav" -Recurse | Move-Item -Destination (get-location + "string")

I know i could just use variables, but i really want to understand this (if there is an answer). Thanks in advance =)

1 Answer 1

2

You could use a sub-expression, like this:

Get-ChildItem -Path ".\*.wav" -Recurse | 
    Move-Item -Destination "$(Get-Location)\foo_1"

The structure $(...) tells PowerShell to execute the contents of the brackets first (i.e. run Get-Location) then substitute the result into the string. Note that you must use double-quotes as this functionality doesn't work with single-quoted strings.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! The $(...) did it for me 🙏

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.