Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 408 Vote(s) - 3.57 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why is PowerShell resolving paths from $home instead of the current directory?

#1
I expect this little powershell one liner to echo a full path to foo.txt, where the directory is my current directory.

[System.IO.Path]::GetFullPath(".\foo.txt")

But it's not. It prints...

C:\Documents and Settings\Administrator\foo.txt

I am not in the $home directory. Why is it resolving there?
Reply

#2
According to the documentation for [GetFullPath][1], it uses the current working directory to resolve the absolute path. The powershell current working directory is not the same as the current location:

PS C:\> [System.IO.Directory]::GetCurrentDirectory()
C:\Documents and Settings\user
PS C:\> get-location

Path
----
C:\

I suppose you could use SetCurrentDirectory to get them to match:

PS C:\> [System.IO.Directory]::SetCurrentDirectory($(get-location))
PS C:\> [System.IO.Path]::GetFullPath(".\foo.txt")
C:\foo.txt


[1]:

[To see links please register here]

Reply

#3
`[System.IO.Path]` is using the shell process' current directory. You can get the absolute path with the `Resolve-Path` cmdlet:

Resolve-Path .\foo.txt
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through