Skip to content

dir -force -hidden c:\pagefile.sys returns an error #2144

Closed

Description

Running as Admin with full PowerShell running on W10 I see:

PS> cmd /c dir /ah c:\pagefile.sys
 Volume in drive C has no label.
 Volume Serial Number is B6ED-8BC6

 Directory of c:\

08/30/2016  06:10 PM     3,758,096,384 pagefile.sys
               1 File(s)  3,758,096,384 bytes
               0 Dir(s)  28,159,082,496 bytes free
PS> dir -Force -Hidden c:\pagefile.sys
dir : Cannot find path 'C:\pagefile.sys' because it does not exist.
At line:1 char:1
+ dir -Force -Hidden c:\pagefile.sys
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\pagefile.sys:String) [Get-ChildItem], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

PS> dir -force -Hidden c:\pag*
dir : Could not find item C:\pagefile.sys.
At line:1 char:1
+ dir -force -Hidden c:\pag*
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\pagefile.sys:String) [Get-ChildItem], IOException
    + FullyQualifiedErrorId : ItemNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.0.10586.494
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.10586.494
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Activity

  1. vors commented on Aug 31, 2016

    @vors
    Collaborator

    Jeffrey Snover (@jpsnover) I updated the issue text and wrapped the console log in the code snippet block. This keeps github from applying markdown formatting rules (i.e. turning

    + dir -Force -Hidden c:\pagefile.sys
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

    into a list:

    • dir -Force -Hidden c:\pagefile.sys
    • 
      

    Please, use this technique and other markdown formatting to format issues.

  2. joeyaiello commented on Sep 6, 2016

    @joeyaiello
    Contributor

    Also seeing this on Anniversary Update:

    Name                           Value
    ----                           -----
    PSVersion                      5.1.14915.1000
    PSEdition                      Desktop
    

    Interestingly, Get-ChildItem -Force shows the pagefile until I get specific.

    Three .sys files here:

    C:\> Get-ChildItem -Force
        Directory: C:\
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    d--hs-         2/6/2016   9:52 AM                $Recycle.Bin
    ...
    d-----         9/2/2016   1:06 PM                Windows
    d-----         9/2/2016   1:05 PM                Windows.old
    -a-hs-         6/1/2016   1:19 AM              1 BOOTNXT
    -a-hs-         9/6/2016  10:07 AM     3294212096 hiberfil.sys
    -a-hs-         9/6/2016  11:04 AM     5766459392 pagefile.sys
    -a-hs-        8/31/2016  12:13 PM       16777216 swapfile.sys
    

    But then this happens:

    C:\> Get-ChildItem -Force *.sys
    Get-ChildItem : Could not find item C:\hiberfil.sys.
    At line:1 char:1
    + Get-ChildItem -Force *.sys
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (C:\hiberfil.sys:String) [Get-ChildItem], IOException
        + FullyQualifiedErrorId : ItemNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
    
    Get-ChildItem : Could not find item C:\pagefile.sys.
    At line:1 char:1
    + Get-ChildItem -Force *.sys
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (C:\pagefile.sys:String) [Get-ChildItem], IOException
        + FullyQualifiedErrorId : ItemNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
    
    Get-ChildItem : Could not find item C:\swapfile.sys.
    At line:1 char:1
    + Get-ChildItem -Force *.sys
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (C:\swapfile.sys:String) [Get-ChildItem], IOException
        + FullyQualifiedErrorId : ItemNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
    
  3. charub commented on Sep 13, 2016

    @charub
    Contributor

    Joey Aiello (@joeyaiello), Jeffrey Snover (@jpsnover) : The scenario only repro's if the path for .sys file is provided.
    When the path is .sys file, underlying native api 'GetFileAttributes' returns 'INVALID_FILE_ATTRIBUTES' (failure) with error code 32 (ERROR_SHARING_VIOLATION = The process cannot access the file because it is being used by another process.) .
    The solution is to use 'FindFirstFile(path)' in case the error code is 32. If it does not return INVALID_HANDLE_VALUE (-1) , the file exists.

  4. daxian-dbw commented on Sep 27, 2016

    @daxian-dbw
    Member

    Closed via #2273

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

Metadata

Metadata

Labels

Issue-BugIssue has been identified as a bug in the productOS-WindowsWG-Cmdletsgeneral cmdlet issues

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions