dir Difficulties


  1. Posts : 331
    windows 10
       #1

    dir Difficulties


    I am seeking to sort files with dir.

    Creation date and time is my most primary interest.

    This has been my primary guide.
    MS-DOS dir command help

    I have tried a number of these commands in Powershell and Admin Powershell

    The simple one element wild card ones work okay. Ex
    dir *.exe

    All the others seem to use methods and techniques beyond my current skill level.

    First. I do not understand this statement.
    Options listed below may be preset in the DIRCMD environment variable. To override preset options, prefix any switch with - (hyphen), for example, "/-W".
    A description and example might help,


    The slash operator returns errors that I do not know how to fix. Ex
    PS G:\> dir /b
    dir : Cannot find path 'G:\b' because it does not exist.

    Why does PS reverse the direction of the slash?

    Any guidance, clearer examples,references,tutorials...will be appreciated.

    Thanks
      My Computer


  2. Posts : 809
    Win10
       #2

    You are using PowerShell (as indicated by the "PS" in the prompt). The PowerShell syntax is different from the "DOS" or CMD.EXE syntax that most people are familiar with.

    You can just run "cmd" in PowerShell to switch to CMD.EXE. If you want to use PowerShell you'll need to find PowerShell-specific references.

    Code:
    PS C:\temp> dir /b
    dir : Cannot find path 'C:\b' because it does not exist.
    At line:1 char:1
    + dir /b
    + ~~~~~~
        + CategoryInfo          : ObjectNotFound: (C:\b:String) [Get-ChildItem], ItemNotFoundException
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
    
    PS C:\temp> cmd
    Microsoft Windows [Version 10.0.17134.112]
    (c) 2018 Microsoft Corporation. All rights reserved.
    
    C:\temp>dir /b
    test
      My Computer


  3. Posts : 16,949
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #3

    Mike,

    1 [error, deleted]

    2 You will get the most up-to-date definition of the command by entering dir /? once you have reached a Command prompt.

    3 Dir does not sort the files, it lists them. The SortOrder switch in Dir affects how they are listed on that occasion. You can also list files in your desired sort order within File explorer.

    4 You can get to a Command prompt window by several methods including that mentioned by PolarNettles. Another method is to use the Start menu where you will find a shortcut to open one in the Windows system group.

    5 You do not have to concern yourself with DirCmd if you do not want to. DirCmd is a variable that can be set up to have a desired value but is, by default, empty & has no effect.
    - I have never known anybody use DirCmd.
    - You will need to study the Set command & the whole subject of environmental variables to get to grips with DirCmd.
    - You can see a brief explanation together with some examples in Change Default Sorting Order of Dir - SuperUser.


    Denis
    Last edited by Try3; 26 Jun 2018 at 09:57.
      My Computer


  4. Posts : 17,661
    Windows 10 Pro
       #4

    Try3 said:
    Dir does not use Creation date-time but LastModified date-time. I do not know of any ready-made tool that uses Creation date.
    DIR uses whatever time definition you tell it to use. Following command would list all files and folders in X:\Downloads in order they have been created:

    dir X:\Downloads /t:c


    Try3 said:
    Dir does not sort the files, it lists them. The SortOrder switch in Dir affects how they are listed on that occasion. You can also list files in your desired sort order within File explorer.

    DIR is fully capable to sort files and folders. Following command would list all files in X:\Downloads, oldest first:

    dir X:\Downloads /o:d

    The minus sign before a parameter reverses the results, so the following command would list the same folder in reversed order, newest first:

    dir X:\Downloads /o:-d

    You can also combine switches. Following command would list all files and folders in X:\Downloads and all its subfolders (the /s switch), listing them in newest first based on time of file / folder creation:

    dir X:\Downloads /s /o:-d /t:c

    Kari
      My Computer


  5. Posts : 16,949
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #5

    Kari,

    Thank you for your first point.

    About your second point, you are agreeing with the sentence of mine that you quote & that you appear to be taking issue with. Dir lists files and its lists can be displayed in several sort orders.

    Denis
      My Computer


  6. Posts : 17,661
    Windows 10 Pro
       #6

    Try3 said:
    About your second point, you are agreeing with the sentence of mine that you quote & that you appear to be taking issue with.
    "Taking issue"? I was just correcting wrong information, a normal reply. No issues.

    That being said, no, I do not agree with you.

    Try3 said:
    Dir does not sort the files, it lists them.
    Using correct parameters, DIR will sort files and folders it lists.

    Kari
      My Computer


  7. Posts : 16,949
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #7

    Kari - We are both saying the same thing. Dir lists files and its lists can be sorted. Dir does not do anything to the files themselves but only to the lists it produces. Denis
      My Computer


  8. Posts : 331
    windows 10
    Thread Starter
       #8

    I am getting the hang of this command set.

    Maybe somebody know a work around that will list the three time stamps at one time.
    Theoretically dir /TC /TA /TW.
    dir will only show one of the three at one time.

    To me it seems that the only way to get all three on a line is to run loop with output to file, then boiling down the three outputs to one line. Clumsy but maybe the only way to get the job done?

    Thanks for any suggestions.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 20:00.
Find Us




Windows 10 Forums