Skip to content

New-Item ignore's Path param if Name param is specified #5228

Description

Steps to reproduce

Set-Location ~
New-Item -Path C:\ -Name Test -ItemType Directory -Verbose

Expected behavior

Test folder created in Root C:\

Actual behavior

Folder created in current path
PS C:\Users\Aftab> New-Item -Path C:\ -Name Test -ItemType Directory -Verbose
VERBOSE: Performing the operation "Create Directory" on target "Destination: C:\Users\Aftab\Test".


    Directory: C:\Users\Aftab


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       25/10/2017     13:51                Test


PS C:\Users\Aftab> Get-Item C:\Test
Get-Item : Cannot find path 'C:\Test' because it does not exist.
At line:1 char:1
+ Get-Item C:\Test
+ ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Test:String) [Get-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand

PS C:\Users\Aftab> Get-Item ~\Test


    Directory: C:\Users\Aftab


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       25/10/2017     13:51                Test

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0-beta.8
PSEdition                      Core
GitCommitId                    v6.0.0-beta.8
OS                             Microsoft Windows 10.0.15063
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    WG-Engine-Providers
    Issue-Bug
    on Oct 25, 2017
  2. affieuk commented on Oct 25, 2017

    @affieuk
    Author

    This also occurs in a mounted a vhdx.

    PS E:\Users> New-Item -Path E:\ -Name Test -ItemType Directory -Verbose
    VERBOSE: Performing the operation "Create Directory" on target "Destination: E:\Users\Test".
    
    
        Directory: E:\Users
    
    
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    d-----       25/10/2017     14:09                Test
    
    
    PS E:\Users> Get-Item E:\Test
    Get-Item : Cannot find path 'E:\Test' because it does not exist.
    At line:1 char:1
    + Get-Item E:\Test
    + ~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (E:\Test:String) [Get-Item], ItemNotFoundException
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand
    
    PS E:\Users> Get-Item Test
    
    
        Directory: E:\Users
    
    
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    d-----       25/10/2017     14:09                Test
    
  3. iSazonov commented on Oct 25, 2017

    @iSazonov
    Collaborator

    Aftab Hussain (@affieuk) Thanks for your report!

    I can confirm that new directory is created in current folder not in Path.

  4. iSazonov commented on Apr 4, 2018

    @iSazonov
    Collaborator

    @mcbobke Thanks for your investigation!
    It can be tricky - there is some code levels - cmdlet, globbing, provider and some abstractions layers. I suggest you to debug starting with New-Item cmdlet code and compare code paths in your samples.

  5. iSazonov commented on Apr 4, 2018

    @iSazonov
    Collaborator

    @mcbobke Do you use latest VS Code version?

  6. iSazonov commented on Apr 5, 2018

    @iSazonov
    Collaborator

    @mcbobke Every provider keep own current directory. In FileSystem provider case the currect directory differ from .Net current directory.

  7. iSazonov commented on Apr 9, 2018

    @iSazonov
    Collaborator

    Should we consider other providers too?

    /cc Michael Klement (@mklement0)

  8. rjmholt commented on Apr 27, 2018

    @rjmholt
    Collaborator

    It looks like the fix for this in #6600 broke some Set-Location behaviour. Fixing this will need to account for Set-Location wanting to restore the path and New-Item wanting to use the path as given. It may be that C: should use the restored path and C:\ should not?

  9. mklement0 commented on Apr 27, 2018

    @mklement0
    Contributor

    Rob Holt (@rjmholt):

    Not really having followed all of this, I'd say you're correct: c: should refer to whatever location is current in that drive, whereas c:\ should refer to the drive's root directory.

    That's how it works in cmd.exe too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugResolution-FixedWG-Engine-Providers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions