How to list directory files timestamps with second and output to a text file ?

Discussion in 'Application Software' started by mdfm, Oct 21, 2013.

  1. mdfm

    mdfm MDL Novice

    Apr 4, 2010
    26
    0
    0
    I know this command C:\>dir /TC- > text.txt at window but it only list the file in date and time but there is no second. hh:mm
    Using this application code.google.com/p/stexbar/ I can clearly see there was a second timestamps hh:mm:ss

    Any reason why dir cannot view the second ?
     
  2. unreal2k3

    unreal2k3 MDL Novice

    Nov 18, 2009
    14
    4
    0
    Because the command does not offer such functionality.

    But you can use Powershell (integrated in Vista and above) to view the full creationtime hh:mm:ss

    get-item * | ft Name,CreationTime | Out-File text.txt
     
  3. mdfm

    mdfm MDL Novice

    Apr 4, 2010
    26
    0
    0
    #3 mdfm, Oct 23, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Thank you , what if I wanted to list it inside a folder including the files with creationtime in second ? and also human readable format size ?
    I try and search "Get-ChildItem" but it come out with just hh:mm without the ss.

    When comes to Dir I know about CD to the folder and listing out the folder with files
    Code:
    dir /S /OGN /TC /A- > C:/test.txt
    I just wanted to list out with creationtime with :SS

    How do I convert the dir above to powershell ? :worthy::worthy:
     
  4. unreal2k3

    unreal2k3 MDL Novice

    Nov 18, 2009
    14
    4
    0
    #4 unreal2k3, Oct 24, 2013
    Last edited by a moderator: Apr 20, 2017
    get-item is not quite correct (my mistake :eek:). Better you use 'get-childitem':

    Code:
    Get-ChildItem -Recurse | ft creationtime,mode,length,name >c:\test.txt
    if you want to know how to use get-childitem:

    Code:
    Get-ChildItem | Get-Member
    get-help get-childitem -online
    
    Hope this helps...
     
  5. mdfm

    mdfm MDL Novice

    Apr 4, 2010
    26
    0
    0
    #5 mdfm, Oct 24, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Thank you very much :worthy:
    How do I sort the ordering ? Such as Alphabetical order or File creation ?
    Would like to know , how to output the length in MB or human readable format ?
    Now reading the ChildItem help file
    Thanks again :biggrin:
     
  6. unreal2k3

    unreal2k3 MDL Novice

    Nov 18, 2009
    14
    4
    0
    #6 unreal2k3, Oct 25, 2013
    Last edited by a moderator: Apr 20, 2017
    To sort an object by a property use 'sort-object' (isn't that easy :) )

    Code:
    get-childitem | sort-object length -descending
    get-childitem | sort-object creationtime
    
    To convert from bytes to MB or kb or GB or whatever use this pattern: @{n='Field';e={[int]($_.Property/1kb)}} with select-object.
    Field is just a Text. Property is from Get-Member (eg. get-childitem | get-member)
    Change KB to MB, GB, TB, PB

    Code:
    get-childitem | sort-object length -descending | select-object name,@{n='Size in kb';e={[int]($_.Length/1kb)}}
    gives the following output:


    Name Size in kb
    ---- ----------
    PsExec.exe 373
    Schema.csv 194
    EnumOpenFiles4.ps1 5
    Terminal.RDP 2
     
  7. mdfm

    mdfm MDL Novice

    Apr 4, 2010
    26
    0
    0
    #7 mdfm, Oct 25, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    I found some code and modified it some of it


    Code:
    
    
    
    I can't get the file name and date creation,lastwritetime to display fully.
    Anyway to fix the code ? what did I miss ?:(

    -Updates

    Going further adding wrap and autosize, I am getting errors from the table code

    1) WARNING: column "GB" does not fit into the display and was removed.
    2) The path didn't get output

    Again , possible to fix the column to fit all inluding the path ? :confused:
     
  8. unreal2k3

    unreal2k3 MDL Novice

    Nov 18, 2009
    14
    4
    0
    You get the path with "fullname" instead of "Name".

    format-table is tied to the output screen, so you have to resize the Screen (Alt + Space -> Properties).
    And remove either warp or autosize. both doesn't work.

    An other option is to use export-csv instead of out-text. This gives you a comma seperated value text file.

    Other possibilities are convertto-html or convertto-XML.

    Or just kick out a column. It makes no sense to have everything in one table. :confused:

    Good luck...
     
  9. mdfm

    mdfm MDL Novice

    Apr 4, 2010
    26
    0
    0
    #9 mdfm, Oct 29, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Ok , thanks for the suggestion.
    There's also an error I encouter , if there's more than 8 sub directory folder with a blank spacing on most of the folder.
    How do I output it ?

    Get-ChildItem : Cannot find path L:\test doc'' because it does not exist.

    :confused: sorry again for bothering
     
  10. mdfm

    mdfm MDL Novice

    Apr 4, 2010
    26
    0
    0
    I tried with some folder , it comes out with
    At line:1 char:14
    Anyone knows what error was it ?