Werbung: SecurityConsole.de verwaltet Ihre Computer mit Security Essentails aus der Cloud!
30 Tage kostenfrei testen und 20% Rabatt für Ihre Bestellung mit Promocode: WBF2685582
(Promocode gültig bis 31.12.2011)

Group:  English: General » microsoft.public.windows.powershell
Thread: Why behaves Join-Path not the pythonic way

HTVi
TV Discussion Newsgroups

Why behaves Join-Path not the pythonic way
Bernd K <guest[ at ]unknown-email.com> 12/28/2008 4:34:32 PM
I was just surprised to see that Join-path $pwd $profile yields C:\Users\berndk\C:\Users\berndk\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1 and doesn't recognize that $profile is an absolut path. I dare say that is an issue. or tell me a usecase where plain concatination is desired. Happy scripting Bernd -- Bernd K
Re: Why behaves Join-Path not the pythonic way
Shay Levy [MVP] <no[ at ]addre.ss> 12/28/2008 7:59:36 PM
Hi Bernd,

I don't know about Python but this is the way join-path work.
You are actually using join-path with positional parameters, as in:


PS > Join-path -path $pwd -childpath $profile


-childpath appends elements to the value of -path, you should provide -childpath
with relative paths. It will also
remove any double leading path seperator characters:


PS > Join-path -path c:\ -childpath \foo
c:\foo

# the same as above
PS > Join-path -path c:\ -childpath foo
c:\foo

---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar



BK> I was just surprised to see that
BK> Join-path $pwd $profile
BK> yields
BK> C:\Users\berndk\C:\Users\berndk\Documents\WindowsPowerShell\Microsof
BK> t.PowerShellISE_profile.ps1
BK> and doesn't recognize that $profile is an absolut path.
BK> I dare say that is an issue.
BK> or tell me a usecase where plain concatination is desired.
BK> Happy scripting
BK> Bernd

Re: Why behaves Join-Path not the pythonic way
Bernd K <guest[ at ]unknown-email.com> 12/28/2008 10:19:17 PM
Hallo Shay, thanks for stressing how Path-Join is designed. I was still thinking too pythonic. (GET-ITEM $FILENAME).FULLNAME transforms perfectly a given relative or absolute path into the absolut path. This helps my to start ISE with some files, load further files into ISE or switch the focus to some already loaded tab. 'See in: PowerShell Code Repository -' (http://poshcode.org/757) The current discoveries not yet included. 'Shay Levy [MVP Wrote: > ;922575']Hi Bernd, > > I don't know about Python but this is the way join-path work. > You are actually using join-path with positional parameters, as in: > > > PS > Join-path -path $pwd -childpath $profile > > > -childpath appends elements to the value of -path, you should provide > -childpath > with relative paths. It will also > remove any double leading path seperator characters: > > > PS > Join-path -path c:\ -childpath \foo > c:\foo > > # the same as above > PS > Join-path -path c:\ -childpath foo > c:\foo > > --- > Shay Levy > Windows PowerShell MVP > 'Shay Levy' (http://blogs.microsoft.co.il/blogs/ScriptFanatic) > PowerShell Toolbar: 'PowerShell at the tip of your browser - Shay Levy' > (http://tinyurl.com/PSToolbar) > > > > BK> I was just surprised to see that > BK> Join-path $pwd $profile > BK> yields > BK> > C:\Users\berndk\C:\Users\berndk\Documents\WindowsPowerShell\Microsof > BK> t.PowerShellISE_profile.ps1 > BK> and doesn't recognize that $profile is an absolut path. > BK> I dare say that is an issue. > BK> or tell me a usecase where plain concatination is desired. > BK> Happy scripting > BK> Bernd -- Bernd K
Re: Why behaves Join-Path not the pythonic way
"Josh Einstein" <josheinstein[ at ]hotmail.com> 12/28/2008 11:04:26 PM
Coming from a .NET background, I too find Join-Path to be a bit too crude.
It's not much better than simple concatenation.

For that reason, I have a function called Join-PathEx that looks like the
following. It's a bit better, but still has some annoying behavior such as
'C:\Temp' '\Windows' joins to '\Windows' instead of 'C:\Windows'. Also it
doesn't attempt to process '..\blah' it just leaves the dots.

function Join-PathEx {

$Path = $null

if ( $args.Length -gt 0 ) {
$Path = $args[0]
for ($i = 1; $i -lt $args.Length; $i++) {
$Path = [System.IO.Path]::Combine($Path, $args[$i])
}
}

$Path

}

Josh Einstein


"Bernd K" <guest[ at ]unknown-email.com> wrote in message
news:cc09318102e8c7b1fc97d5e7e5e7305c[ at ]nntp-gateway.com...
[Quoted Text]
>
> Hallo Shay,
>
> thanks for stressing how Path-Join is designed.
>
> I was still thinking too pythonic.
>
> (GET-ITEM $FILENAME).FULLNAME
> transforms perfectly a given relative or absolute path into the absolut
> path.
>
> This helps my to start ISE with some files, load further files into ISE
> or switch the focus to some already loaded tab.
>
> 'See in: PowerShell Code Repository -' (http://poshcode.org/757)
>
> The current discoveries not yet included.
>
>
> 'Shay Levy [MVP Wrote:
>> ;922575']Hi Bernd,
>>
>> I don't know about Python but this is the way join-path work.
>> You are actually using join-path with positional parameters, as in:
>>
>>
>> PS > Join-path -path $pwd -childpath $profile
>>
>>
>> -childpath appends elements to the value of -path, you should provide
>> -childpath
>> with relative paths. It will also
>> remove any double leading path seperator characters:
>>
>>
>> PS > Join-path -path c:\ -childpath \foo
>> c:\foo
>>
>> # the same as above
>> PS > Join-path -path c:\ -childpath foo
>> c:\foo
>>
>> ---
>> Shay Levy
>> Windows PowerShell MVP
>> 'Shay Levy' (http://blogs.microsoft.co.il/blogs/ScriptFanatic)
>> PowerShell Toolbar: 'PowerShell at the tip of your browser - Shay Levy'
>> (http://tinyurl.com/PSToolbar)
>>
>>
>>
>> BK> I was just surprised to see that
>> BK> Join-path $pwd $profile
>> BK> yields
>> BK>
>> C:\Users\berndk\C:\Users\berndk\Documents\WindowsPowerShell\Microsof
>> BK> t.PowerShellISE_profile.ps1
>> BK> and doesn't recognize that $profile is an absolut path.
>> BK> I dare say that is an issue.
>> BK> or tell me a usecase where plain concatination is desired.
>> BK> Happy scripting
>> BK> Bernd
>
>
> --
> Bernd K

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net
Suche nach Orten, Städten, Postleitzahlen, Vorwahlen, Kfz-Kennzeichen