How to display seconds with the DIR command?

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
User avatar
Peter
Power Member
Power Member
Posts: 2068
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

How to display seconds with the DIR command?

Post by *Peter »

I use DIR > file.txt to get a list of files, including time stamps. Is there under Windows XP a way to create a txt-file with the seconds also displayed in the time stamps of the file list?

regards

Peter
TC 10.xx / #266191
Win 10 x64
bobputnam
Junior Member
Junior Member
Posts: 77
Joined: 2003-05-26, 12:31 UTC
Location: Connecticut, USA

Post by *bobputnam »

Try xdir freeware.
Bob P
3-User License 71012
User avatar
Peter
Power Member
Power Member
Posts: 2068
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

Post by *Peter »

bobputnam wrote:Try xdir freeware.
Thanks, but I have to avoid any kind of additional software (otherwise I would use TC.) Is there a way with "basic CMDs from Win XP"?

Peter
TC 10.xx / #266191
Win 10 x64
Jack!
Junior Member
Junior Member
Posts: 11
Joined: 2009-05-19, 08:05 UTC

Post by *Jack! »

Here's an alternative way. Copy the file path (example c:\windows) in to the address bar of Firefox or Chrome et voilà, you'll see a file list including a time stamp with seconds.
Semper nocuit differre paratis.
User avatar
Peter
Power Member
Power Member
Posts: 2068
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

Post by *Peter »

Jack! wrote:Here's an alternative way. Copy the file path (example c:\windows) in to the address bar of Firefox or Chrome et voilà, you'll see a file list including a time stamp with seconds.
Yeah - that looks remarkable. But what's about displaying recursive subdirs?

Peter
TC 10.xx / #266191
Win 10 x64
Sob
Power Member
Power Member
Posts: 945
Joined: 2005-01-19, 17:33 UTC

Post by *Sob »

If you can't use any other software, then the answer is built-in Windows scripting.

Try something like this, save it to mydir.vbs:

Code: Select all

Set objFSO = CreateObject("Scripting.FileSystemObject")

If WScript.Arguments.Count = 0 Then
  strFolder = objFSO.GetAbsolutePathName(".")
  isRec = False
Else
  If WScript.Arguments.Count = 1 Then
    If WScript.Arguments(0) = "/rec" Then
      strFolder = objFSO.GetAbsolutePathName(".")
      isRec = True
    Else
      strFolder = objFSO.GetAbsolutePathName(WScript.Arguments(0))
      isRec = False
    End If
  Else  
    strFolder = objFSO.GetAbsolutePathName(WScript.Arguments(0))
    If WScript.Arguments(1) = "/rec" Then
      isRec = True
    Else
      isRec = False
    End If
  End If  
End If

GetFiles strFolder

Function GetFiles(byval strDirectory)
  WScript.StdOut.WriteLine "Listing of " & strDirectory
  Set objFolder = objFSO.GetFolder(strDirectory)
  For Each objFile In objFolder.Files
    WriteItemLine objFile, False
  Next
  If isRec Then
    For Each objFolder In objFolder.SubFolders
      WriteItemLine objFolder, True
      GetFiles objFolder.Path
    Next
  End If  
End Function

Function WriteItemLine(byref objFile, byval isFolder)
  strLine = ""
  strLine = strLine & objFile.DateLastModified & ", "
  If isFolder Then
    strLine = strLine & "directory, "
  Else
    strLine = strLine & "file, "
  End If
  strLine = strLine & objFile.Size & ", "
  strLine = strLine & objFile.Name
  WScript.StdOut.WriteLine strLine
End Function
Usage examples:

Code: Select all

cscript //B //U mydir.vbs > current-dir.txt
cscript //B //U mydir.vbs C:\Temp > some-other-dir.txt
cscript //B //U mydir.vbs /rec > current-dir-recursive.txt
cscript //B //U mydir.vbs C:\Temp /rec > some-other-dir-recursive.txt
If you don't like the format, it's easy to change.
User avatar
Peter
Power Member
Power Member
Posts: 2068
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

Post by *Peter »

Peter wrote:Yeah - that looks remarkable. But what's about displaying recursive subdirs?

Peter
I asked in FireFox-Forum - there seem to be no solution ...

2Sob
thanks, I will test it in the next days.

Peter
TC 10.xx / #266191
Win 10 x64
User avatar
dott
Senior Member
Senior Member
Posts: 285
Joined: 2007-03-04, 00:58 UTC
Location: La Plata, Argentina

Post by *dott »

I see your request and still need to say: use one of gnu ls ports for windows. The net is plagued by forum request on this topic, some from you I believe, dir.exe can't do that.
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

Here's the most up to date one that I know of on google code UnxUtils

If installed, Add the wbin folder to Windows Path, or create a junction to it, and add that to the path.
I recommend renaming echo, find, date and type to gecho.exe, gfind.exe (etc).


All the files included:
[face=trebuchetms]agrep.exe
ansi2knr.exe
basename.exe
bc.exe
bison.exe
bunzip2.exe
bzip2.exe
bzip2recover.exe
cat.exe
chgrp.exe
chmod.exe
chown.exe
cksum.exe
cmp.exe
comm.exe
compress.exe
cp.exe
csplit.exe
cut.exe
date.exe
dc.exe
dd.exe
df.exe
diff.exe
diff3.exe
dircolors.exe
dirname.exe
du.exe
echo.exe
egrep.exe
env.exe
expand.exe
expr.exe
factor.exe
fgrep.exe
find.exe
flex.exe
fmt.exe
fold.exe
fsplit.exe
gawk.exe
gclip.exe
gplay.exe
grep.exe
gsar.exe
gunzip.exe
gzip.exe
head.exe
id.exe
indent.exe
install.exe
join.exe
jwhois.exe
less.exe
lesskey.exe
libfl.a
libfl.lib
ln.exe
logname.exe
ls.exe
m4.exe
make.exe
makedepend.exe
makemsg.exe
man.exe
md5sum.exe
mkdir.exe
mkfifo.exe
mknod.exe
mv.exe
mvdir.exe
nl.exe
od.exe
paste.exe
patch.exe
pathchk.exe
pclip.exe
pr.exe
printenv.exe
printf.exe
ptx.exe
pwd.exe
recode.exe
rm.exe
rman.exe
rmdir.exe
sdiff.exe
sed.exe
seq.exe
sha1sum.exe
shar.exe
sleep.exe
sort.exe
split.exe
stego.exe
su.exe
sum.exe
sync.exe
tac.exe
tail.exe
tar.exe
tee.exe
test.exe
touch.exe
tr.exe
tsort.exe
type.exe
uname.exe
unexpand.exe
uniq.exe
unrar.exe
unshar.exe
unzip.exe
uudecode.exe
uuencode.exe
wc.exe
wget.exe
wget.hlp
which.exe
whoami.exe
xargs.exe
yes.exe
zcat.exe
zip.exe
zsh.exe[/face]
User avatar
dott
Senior Member
Senior Member
Posts: 285
Joined: 2007-03-04, 00:58 UTC
Location: La Plata, Argentina

Post by *dott »

[OT]

I will recommend MSYS base system(~7 MB), the UnxUtils are from 1998 to 2003.

MSYS installer : http://downloads.sourceforge.net/project/mingw/MSYS/BaseSystem/msys-1.0.11/MSYS-1.0.11.exe?use_mirror=sunet

[OT]
Last edited by dott on 2010-06-16, 06:37 UTC, edited 1 time in total.
Probablemente no
User avatar
ehab
Senior Member
Senior Member
Posts: 271
Joined: 2007-10-29, 07:41 UTC
Location: Libya

Post by *ehab »

Balderstrom Excellent you mentioned UnxUtils, will start to use right away. thank you

8)

dott will check out MSYS
#181344 Personal licence
User avatar
dorin
Junior Member
Junior Member
Posts: 6
Joined: 2017-06-10, 11:29 UTC
Location: italy

Re:Very bad news - see 3

Post by *dorin »

Sob wrote: 2010-06-15, 14:30 UTC cscript //B //U mydir.vbs /rec > current-dir-recursive.txt
I gave up the parameter //B because it hides errors like "Permission Denied" when executing objFile.Size
Workaround - I run the script command using "Run as Administrator" window
I tried some error handling procedures without success
1. Try Catch is not yet implemented in cscript (version 5.812) even it is advertised by Microsoft (but maybe it works work only inside the MS Studio and was not implemented in cscript, yet)
2. the old VBA exception method "on Error Resume Next" is not working for Permission Denied
I could not catch the error and the effect is that it loses all the files after the error
In my case, the first directory was the known "Recycle Bin" so no other subdirectory was included in the listing as the program crashed early
3. Very bad news - the VBA software crashed for path length over 256 characters

Code: Select all

objFile.Size
"Microsoft VBScript runtime error: Path not found"
3.2 Even if you execute

Code: Select all

On Error Resume Next
The long paths are not included in the

Code: Select all

objFolder.SubFolders
So you can not repair it
I have to write my own program in a different Programming Language

Thank you for your solution - it is fast even for my million files on many HDD (not as fast as DIR but I found too many problems in DIR (seconds, date format change between computers and time zone changes ....))
At least in your solution, you can develop something independent of computer and time zone :wink: even if the result comes after 1 or 2 hours
NotNull
Senior Member
Senior Member
Posts: 298
Joined: 2019-11-25, 20:43 UTC
Location: NL

Re: How to display seconds with the DIR command?

Post by *NotNull »

An alternative in CMD:

Run secondtime.cmd "c:\some folder\" to get similar output like below. Parse the results ffurther from there.
Make sure the foldername ends with a "\" (or change the code).
It should be fast.
Personally, I would use PowerShell for this.

Code: Select all


C:\Temp>secondtime.cmd "c:\Test\emed64_18.7.2_portable\"
Extension  FileName       FileSize  LastModified               Path
exe        eeadmin        213752    20190327223308.000000+060  \test\emed64_18.7.2_portable\
ini        eecommon       22606     20190624085751.813939+120  \test\emed64_18.7.2_portable\
ini        eeconfig       776120    20190518015958.877174+120  \test\emed64_18.7.2_portable\
ini        eelm           2         20190414002324.962960+120  \test\emed64_18.7.2_portable\
dll        eemacro        1080056   20190327223322.000000+060  \test\emed64_18.7.2_portable\
tlb        eemacro        82996     20190327223220.000000+060  \test\emed64_18.7.2_portable\
ini        eePlugins      170       20190518014633.361255+120  \test\emed64_18.7.2_portable\
ini        eeuseini       0         20190327224112.137600+060  \test\emed64_18.7.2_portable\
dll        emedcfd        2575608   20190327223306.000000+060  \test\emed64_18.7.2_portable\
dll        emedcfg        865528    20190327223312.000000+060  \test\emed64_18.7.2_portable\
dll        emeddlgs       975096    20190327223420.000000+060  \test\emed64_18.7.2_portable\
dll        emeddlgt       682232    20190327223256.000000+060  \test\emed64_18.7.2_portable\
exe        emedhtml       138488    20190327223218.000000+060  \test\emed64_18.7.2_portable\
exe        emeditor       22645496  20190327223938.000000+060  \test\emed64_18.7.2_portable\




secondtime.cmd

Code: Select all

@echo off & setlocal

   set "THISPATH=%~pnx1"
   set "WHERE=Drive='%~d1' AND Path='%THISPATH:\=\\%'"
   wmic.exe datafile WHERE "%WHERE%" get Path,FileName,Extension, FileSize,LastModified

Post Reply