1.

Solve : Returning the date and time on file?

Answer»

I picked up this CODE from Salmon Trout from another post.  When I look at files on my desktop the date and time are echoed fine.  When I TRY to look at files on another drive or a server I get no echo at all.

Any thoughts?

echo off
for /f "delims=" %%A in ( 'dir /b /a-d /od c\:docume~1\[username]\desktop\[filename]' ) do (
   set fdate=%%~tA
      )
echo %fdate%I believe the ~t variable modifier only works on local drives. What HAPPENS if you try to get a full DIR listing (not using /b) of the folder? I mean this style of listing...

Code: [Select]Volume in drive C is Win07
 Volume Serial Number is E4DB-A92A

 Directory of C:\

24/09/2010  06:26 PM             1,024 .rnd
19/06/2010  03:16 PM             1,414 backup.log
28/03/2010  10:46 PM               956 dir.txt
06/10/2010  05:35 PM     3,169,705,984 hiberfil.sys
02/01/2010  08:03 PM            57,310 Logon001.jpg
14/03/2010  09:52 PM             1,106 makespecialfolders.bat
03/03/2007  05:44 PM            15,658 mike.jpg
28/03/2010  10:45 PM               870 mike.jpg.lnk
06/10/2010  05:35 PM       314,572,800 pagefile.sys
13/07/2010  06:26 PM       111,562,752 PM11_Pers_full_ea_x64.msi
29/07/2010  10:47 PM                79 whatever.scf
              12 File(s)  3,595,930,401 bytes
               0 Dir(s)  72,403,623,936 bytes freeWhen I get the full listing I have the file names and dates and TIMES as you have shown.  When I use the /b switch I just get the names. Quote

When I get the full listing I have the file names and dates and times as you have shown.

If you can show me (by copy and paste) the format of such a listing I can tell you how to extract the date and time information. I need to see this to know the character positions. It looks from your code as if you require the date and time of the last (LATEST) file in the folder.

Here it is

 Volume in drive C has no label.
 Volume Serial Number is 984C-4C03

 Directory of C:\D_Drive\workspaces\0102\batch\gisdb\wad

10/07/2010  10:39 AM              .
10/07/2010  10:39 AM              ..
10/28/2009  03:34 PM               193 0102bsav.addr
09/16/2007  03:32 PM               193 0102bsav.bld
08/10/2010  11:30 AM         1,543,341 0102bsav.dbf
08/10/2010  11:30 AM                 2 0102bsav.lab
10/28/2009  03:34 PM               193 0102bsav.sub
10/05/2010  08:48 AM            50,684 0102ds.addr
10/28/2009  01:33 PM               288 0102ds.alt
09/16/2007  03:32 PM               193 0102ds.bld
10/06/2010  12:03 PM         1,234,550 0102ds.dbf
10/06/2010  12:03 PM                 2 0102ds.lab
10/06/2010  11:40 AM         9,278,082 0102ds.seq
10/01/2010  12:50 PM            19,634 0102ds.sub
10/07/2010  10:39 AM                 0 myfile.txt
              13 File(s)     12,127,355 bytes
               2 Dir(s)  10,652,610,560 bytes free Code: [Select]
echo off
setlocal enabledelayedexpansion
set dirname="S:\Test"
set dirswitches=/a-d /od
for /f "tokens=1-4* delims= " %%A in ('dir %dirswitches% "%dirname%" ^| findstr /v "File(s) Dir(s) Volume Directory"') do (
    set fdate=%%A
    set ftime=%%B
    set AM-PM=%%C
    set fname=%%E
    )
echo File date %fdate%
echo File time %ftime% %AM-PM%
echo File name %fname%   


Discussion

No Comment Found