3

I have this:

 Get-ChildItem c:\H\admin\contents 

Is it possible to do the same thing but relative to the folder that the powershell script runs in. Sometimes I have the script running in c\H\admin and sometimes in the c\H\user directory so I would prefer not to have to change all the paths in my scripts.

1

1 Answer 1

6

Yes, you can use relative paths.

Get-ChildItem . 

refers to the current directory, c:\H\admin\contents.

Get-ChildItem .. 

refers to the parent directory, c:\H\admin

Get-ChildItem ..\.. 

refers to the parent of the parent, c:\H

You can use relative paths related to a specific path:

Get-ChildItem c:\H\admin\..\users 

which would refer to the folder c:\H\users

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

5 Comments

There has to be a dupe for this.
@Matt: Apparently you didn't find one, or you would have voted to close the question instead of commenting on an answer. :-) Thanks for your support.
Not so fast.... I am looking for one.
Great. Thanks for the information. Can I look at every answer you've ever posted that might have a dupe as well, and inform you every step of the way? Or, better yet: Can I ask why you're telling me that the poster may have posted a duplicate, rather than telling the poster? I didn't post the question.
I'm sure you are aware there is nothing wrong with dupes... I'm sure there are a bunch of mine somewhere especially the earlier ones. It doesn't make the answers wrong? Body language is lost in text but I didn't think I was saying anything wrong... Sorry about that.