≡ Menu

Get file creation date and time

We can find creation date of a file from command line using dir command.  The syntax for this is given below.

dir /T:C filename

If we need to get file creation date and time for all the files and subdirectories in the current directory, the command is:

dir /T:C

We can also restrict the output to specific file types using wildcards.

dir /T:C  *.pdf

The above command would print file creation dates only for pdf files.

Command to print file creation date and time only for files(skip directories)

dir /A:-D /T:C

Find the latest created file in a directory:
The below command would print the files in the order of creation date & time. In this list the file that is created very recently would be displayed in the last position.

dir /A:-D /T:C /O:D

Example:

C:\>dir /A:-D /T:C /O:D
02/06/2012  07:38 PM                 4 4.txt
02/06/2012  07:39 PM                 0 5.txt
02/06/2012  10:45 PM                13 10.txt
02/06/2012  10:47 PM                13 newfile.t
02/11/2012  08:24 PM                83 2.bat
02/11/2012  08:26 PM             5,219 data.txt
02/11/2012  08:27 PM             5,219 data2.txt
02/12/2012  11:28 PM                98 3.bat
02/13/2012  10:47 AM               131 echo.bat
3 comments… add one
  • KoLuNar

    Is it possible to load files with created date using xp_cmdshell in SQL Server ?
    I have asked a question on stackoverflow, please kindly see the link below http://stackoverflow.com/q/32293517/3327081

  • pp

    The dir command seems to always output the creation date of files. The /T switch only tells on which date field to sort the output on. This has only effect if you use it with the /o:d option:
    dir /t:a /o:d
    will sort the files according to ther lastaccessed date, but will output the creation date for all.

  • Gary Campbell

    I used these commands, but the times are the same for many files. When I look at the Date and/or Media Created columns in a Windows folder, I can see the correct creation date and times for the files.

Leave a Comment