How to get file's last modified date on Windows command line?

前端 未结 8 1639
星月不相逢
星月不相逢 2020-12-01 04:16

I have been using the following command to get the file date. However, the fileDate variable has been returning blank value ever since we moved to a different s

8条回答
  •  青春惊慌失措
    2020-12-01 04:32

    You could try the 'Last Written' time options associated with the DIR command

    /T:C -- Creation Time and Date
    /T:A -- Last Access Time and Date
    /T:W -- Last Written Time and Date (default)

    DIR /T:W myfile.txt
    

    The output from the above command will produce a variety of additional details you probably wont need, so you could incorporate two FINDSTR commands to remove blank lines, plus any references to 'Volume', 'Directory' and 'bytes':

    DIR /T:W myfile.txt | FINDSTR /v "^$" | FINDSTR /v /c:"Volume" /c:"Directory" /c:"bytes"
    

    Attempts to incorporate the blank line target (/c:"^$" or "^$") within a single FINDSTR command fail to remove the blank lines (or produce other errors) when the results are output to a text file.

    This is a cleaner command:

    DIR /T:W myfile.txt | FINDSTR /c:"/"
    

提交回复
热议问题