Reputation: 7547
I want to use dir command and have filename as 1st column, creation date time as 2nd column and modified date time as 3rd column.
How could I achieve this?
http://www.computerhope.com/dirhlp.htm
This shows /T
might be used but not sure how to use it because dir /TCAW
doesn't list the format I need.
Upvotes: 3
Views: 12544
Reputation: 151
@ ECHO OFF
(FOR /f "delims=" %%a IN ('dir /b /a-d') DO (
FOR /f "tokens=1-3*" %%x IN ('dir /a-d /tc "%%~a"^|findstr "^[0-9]"') DO (
ECHO "%%a",%%~ta,%%x %%y %%z
)
)) > DIR.txt
TYPE DIR.txt
the answer in refered to : Windows batch file to create csv list of file and dates
Upvotes: 0
Reputation: 130819
As Christopher Painter says, the DIR command cannot do this directly.
But there is a simple command line one liner that displays your information without header or footer info. This command lists only files. It works as long as your locality displays time stamps using 3 space delimited components. For example, my U.S. time stamps display as mm/dd/yyyy hh:mm:ss am
.
for /f "tokens=1-4*" %A in ('dir /a-d /tc^|findstr "^[0-9]"') do @echo %E %A %B %C %~tE
Change /a-d
to /a
if you want to include directories. Or simply remove /a-d
entirely if you want both files and directories but you want to exclude hidden and system files/directories.
Here is the same command in a nicely formatted batch script:
@echo off
for /f "tokens=1-4*" %%A in (
'dir /a-d /tc^|findstr "^[0-9]"'
) do echo %%E %%A %%B %%C %%~tE
I don't like the output format with the file name in the front because the width of the name varies - it is hard to read the output because the columns don't line up. I prefer to put the file name at the end:
@echo off
for /f "tokens=1-4*" %%A in (
'dir /a-d /tc^|findstr "^[0-9]"'
) do echo %%A %%B %%C %%~tE %%E
Upvotes: 6
Reputation: 55581
DIR doesn't support what you are trying to do. the /T:Fileld ID can only show one set of time information at a time. I'm not sure what you are trying to do but I see you have some C# experience. You could write your only console app that outputs the way you out and call that instead.
Upvotes: 3