

InterviewSolution
Saved Bookmarks
1. |
Solve : Returning the date and time on file? |
Answer» <html><body><p>I picked up this <a href="https://interviewquestions.tuteehub.com/tag/code-25512" style="font-weight:bold;" target="_blank" title="Click to know more about CODE">CODE</a> from Salmon Trout from another post. When I look at files on my desktop the date and time are echoed fine. When I <a href="https://interviewquestions.tuteehub.com/tag/try-1428546" style="font-weight:bold;" target="_blank" title="Click to know more about TRY">TRY</a> to look at files on another drive or a server I get no echo at all.<br/><br/>Any thoughts?<br/><br/>echo off<br/>for /f "delims=" %%A in ( 'dir /b /a-d /od c\:docume~1\[username]\desktop\[filename]' ) do (<br/> set fdate=%%~tA<br/> )<br/>echo %fdate%I believe the ~t variable modifier only works on local drives. What <a href="https://interviewquestions.tuteehub.com/tag/happensbrbr-2691586" style="font-weight:bold;" target="_blank" title="Click to know more about HAPPENS">HAPPENS</a> if you try to get a full DIR listing (not using /b) of the folder? I mean this style of listing...<br/><br/> Code: <a>[Select]</a>Volume in drive C is Win07<br/> Volume Serial Number is E4DB-A92A<br/><br/> Directory of C:\<br/><br/>24/09/2010 06:26 PM 1,024 .rnd<br/>19/06/2010 03:16 PM 1,414 backup.log<br/>28/03/2010 10:46 PM 956 dir.txt<br/>06/10/2010 05:35 PM 3,169,705,984 hiberfil.sys<br/>02/01/2010 08:03 PM 57,310 Logon001.jpg<br/>14/03/2010 09:52 PM 1,106 makespecialfolders.bat<br/>03/03/2007 05:44 PM 15,658 mike.jpg<br/>28/03/2010 10:45 PM 870 mike.jpg.lnk<br/>06/10/2010 05:35 PM 314,572,800 pagefile.sys<br/>13/07/2010 06:26 PM 111,562,752 PM11_Pers_full_ea_x64.msi<br/>29/07/2010 10:47 PM 79 whatever.scf<br/> 12 File(s) 3,595,930,401 bytes<br/> 0 Dir(s) 72,403,623,936 bytes freeWhen I get the full listing I have the file names and dates and <a href="https://interviewquestions.tuteehub.com/tag/times-344892" style="font-weight:bold;" target="_blank" title="Click to know more about TIMES">TIMES</a> as you have shown. When I use the /b switch I just get the names. Quote</p><blockquote>When I get the full listing I have the file names and dates and times as you have shown.</blockquote> <br/>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 (<a href="https://interviewquestions.tuteehub.com/tag/latest-1069479" style="font-weight:bold;" target="_blank" title="Click to know more about LATEST">LATEST</a>) file in the folder.<br/><br/>Here it is<br/><br/> Volume in drive C has no label.<br/> Volume Serial Number is 984C-4C03<br/><br/> Directory of C:\D_Drive\workspaces\0102\batch\gisdb\wad<br/><br/>10/07/2010 10:39 AM .<br/>10/07/2010 10:39 AM ..<br/>10/28/2009 03:34 PM 193 0102bsav.addr<br/>09/16/2007 03:32 PM 193 0102bsav.bld<br/>08/10/2010 11:30 AM 1,543,341 0102bsav.dbf<br/>08/10/2010 11:30 AM 2 0102bsav.lab<br/>10/28/2009 03:34 PM 193 0102bsav.sub<br/>10/05/2010 08:48 AM 50,684 0102ds.addr<br/>10/28/2009 01:33 PM 288 0102ds.alt<br/>09/16/2007 03:32 PM 193 0102ds.bld<br/>10/06/2010 12:03 PM 1,234,550 0102ds.dbf<br/>10/06/2010 12:03 PM 2 0102ds.lab<br/>10/06/2010 11:40 AM 9,278,082 0102ds.seq<br/>10/01/2010 12:50 PM 19,634 0102ds.sub<br/>10/07/2010 10:39 AM 0 myfile.txt<br/> 13 File(s) 12,127,355 bytes<br/> 2 Dir(s) 10,652,610,560 bytes free Code: <a>[Select]</a><br/>echo off<br/>setlocal enabledelayedexpansion<br/>set dirname="S:\Test"<br/>set dirswitches=/a-d /od<br/>for /f "tokens=1-4* delims= " %%A in ('dir %dirswitches% "%dirname%" ^| findstr /v "File(s) Dir(s) Volume Directory"') do (<br/> set fdate=%%A<br/> set ftime=%%B<br/> set AM-PM=%%C<br/> set fname=%%E<br/> )<br/>echo File date %fdate%<br/>echo File time %ftime% %AM-PM%<br/>echo File name %fname% <br/></body></html> | |