Skip to content

When creating file using -Path c: without a backslash, file created in the drive root and not in the current folder. #7048

Closed

Description

@sethvs

Steps to reproduce

PS C:\Folder> New-Item -Path c: -Name testfile.txt

Expected behavior

File is created in the C:\Folder directory

Actual behavior

File is created in the root of the drive c:\

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.1.0-preview.705
PSEdition                      Core
GitCommitId                    v6.1.0-preview.705
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. kilasuit commented on Jun 12, 2018

    @kilasuit
    Collaborator

    Sergey Vasin (@sethvs) - I Don't think this is an issue as this is expected behaviour because you are telling New-item to create the file in the C: directory

    If you leave off -Path C: it will create that file in the current directory which in this case is C:\Folder

  2. added
    Issue-Discussion
    WG-Engine-Providers
    on Jun 13, 2018
  3. sethvs commented on Jun 13, 2018

    @sethvs
    ContributorAuthor

    Ryan Yates (@kilasuit) It is not the expected behavior, because it worked the way I specified in version 6.1.0-preview.2 and earlier.
    This was changed in #6774, I believe.

  4. kilasuit commented on Jun 13, 2018

    @kilasuit
    Collaborator

    Sergey Vasin (@sethvs) - I think this is expected behaviour and your use is more of an incorrect edge use case than being an actual issue - because you are explicitly telling New-Item what Path you want it to create in which is C: - as far as i know this is how New-Item has worked since v3 and whist it never crosses my mind to ever use drive directories without the slash this I don't think is unexpected behaviour in the slightest

    if you had

    New-Item -Path C:\folder1\folder2\ -Name testfile.txt

    this will create the file in C:\folder1\folder2\ which is in my opinion exactly as it was designed to do so and ergo is the designed and expected behaviour.

    However if you do this

    Set-Location C:\folder1\
    New-Item -Path .\folder2\ -Name testfile.txt

    this creates this in the folder2 directory as intended

    also take this example

    Set-location HKLM:\
    New-Item -Path C:\temp -Name Test.ps1 -Value '$pwd'

    You would not expect a ps1 file to be created in HKLM - or would you?

  5. iSazonov commented on Jun 14, 2018

    @iSazonov
    Collaborator

    I'd add that the behavior came from cmd.exe - dir c: works as dir c:\.

  6. sethvs commented on Jun 14, 2018

    @sethvs
    ContributorAuthor

    Guys, please pay attention:

    Windows PowerShell 5.1: file is created in current path - C:\Folder

    [5.1] PS C:\Folder> New-Item -Path c: -Name testfile.txt
    
    
        Directory: C:\Folder
    
    
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    -a----        6/14/2018  12:30 PM              0 testfile.txt
    

    PowerShell Core 6.0.2: file is created in current path - C:\Folder

    [6.0.2] PS C:\Folder> New-Item -Path c: -Name testfile.txt
    
    
        Directory: C:\Folder
    
    
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    -a----        6/14/2018  12:32 PM              0 testfile.txt
    

    PowerShell Core 6.1.0-preview.2: file is created in current path - C:\Folder

    [6.1.0-preview.2] PS C:\Folder> New-Item -Path c: -Name testfile.txt
    
    
        Directory: C:\Folder
    
    
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    -a----        6/14/2018  12:28 PM              0 testfile.txt
    

    PowerShell Core 6.1.0-preview.3: file is created in root path - C:\

    [6.1.0-preview.3] PS C:\Folder> New-Item -Path c: -Name testfile.txt
    
    
        Directory: C:\
    
    
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    -a----        6/14/2018  12:29 PM              0 testfile.txt
    

    Again, this was changed with PR #6774.
    My fix for this is in #7033.

  7. sethvs commented on Jun 14, 2018

    @sethvs
    ContributorAuthor

    Ilya (@iSazonov) Nope.

    dir c:\ lists the root of the drive

    C:\Folder>dir c:\
     Volume in drive C has no label.
     Volume Serial Number
    
     Directory of c:\
    
    06/13/2018  11:02 AM    <DIR>          Program Files
    05/30/2018  09:08 AM    <DIR>          Program Files (x86)
    12/28/2017  04:25 PM    <DIR>          Temp
    05/13/2018  05:43 PM    <DIR>          Users
    05/13/2018  06:00 PM    <DIR>          Windows
    
    etc...
    

    while dir c: lists current folder

    C:\Folder>dir c:
     Volume in drive C has no label.
     Volume Serial Number
    
     Directory of C:\Folder
    
    06/14/2018  12:32 PM    <DIR>          .
    06/14/2018  12:32 PM    <DIR>          ..
    06/14/2018  12:32 PM                 0 testfile.txt
                   1 File(s)              0 bytes
                   2 Dir(s)
    
  8. iSazonov commented on Jun 14, 2018

    @iSazonov
    Collaborator

    Sergey Vasin (@sethvs) Please update the PR description with the samples..

  9. sethvs commented on Jun 14, 2018

    @sethvs
    ContributorAuthor
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-DiscussionResolution-FixedWG-Engine-Providers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions