

InterviewSolution
Saved Bookmarks
1. |
Solve : How to get the last modified date of a file into a textfile? |
Answer» <html><body><p>Hi all,<br/><br/>I am very poor in writting batch files, but I want to get the last modified date of a file into a text file.<br/><br/>Could you please <a href="https://interviewquestions.tuteehub.com/tag/provide-607804" style="font-weight:bold;" target="_blank" title="Click to know more about PROVIDE">PROVIDE</a> me the code for that.<br/><br/><br/><br/><a href="https://interviewquestions.tuteehub.com/tag/thanks-665909" style="font-weight:bold;" target="_blank" title="Click to know more about THANKS">THANKS</a> in advance<br/>SarayuThis may help:<br/><br/> Code: <a>[Select]</a>echo off<br/>for /f "skip=5" %%x in ('dir /tw drive:\path\filename.extension') do (<br/> echo %%x > text.file<br/> goto :eof<br/>)<br/><br/>Be sure to change drive:\path\filename.extension to <a href="https://interviewquestions.tuteehub.com/tag/something-25913" style="font-weight:bold;" target="_blank" title="Click to know more about SOMETHING">SOMETHING</a> appropriate.<br/><br/>Good luck. Alternatively<br/> Code: <a>[Select]</a>for /f %%T in ('dir /b filename.ext') do echo %%~tT>text.fileHi,<br/><br/>I am <a href="https://interviewquestions.tuteehub.com/tag/modifying-1099984" style="font-weight:bold;" target="_blank" title="Click to know more about MODIFYING">MODIFYING</a> the code and when I echo the results I get unwanted lines:<br/><br/>:laptop<br/>set localdrv=d:\workspaces<br/>for /f "skip=5" %%i in ('dir /tw %localdrv%\%plantid%\batch\gisdb\wad\%plantid%%wad%.dbf') do (echo %plantid%%wad%.dbf %%i Laptop) <br/><br/>The mod date echoes correctly but I get 2 extra lines after the date is <a href="https://interviewquestions.tuteehub.com/tag/echoed-7679852" style="font-weight:bold;" target="_blank" title="Click to know more about ECHOED">ECHOED</a><br/>[myfilename] 1<br/>[myfilename] 0<br/><br/>How can I eliminate those last 2 lines?<br/><br/>Thanks in advance<br/><br/> Quote from: mcgriff1969 on August 06, 2010, 09:19:23 AM</p><blockquote>Hi,<br/><br/>I am modifying the code and when I echo the results I get unwanted lines:<br/><br/>:laptop<br/>set localdrv=d:\workspaces<br/>for /f "skip=5" %%i in ('dir /tw %localdrv%\%plantid%\batch\gisdb\wad\%plantid%%wad%.dbf') do (echo %plantid%%wad%.dbf %%i Laptop) <br/><br/>The mod date echoes correctly but I get 2 extra lines after the date is echoed<br/>[myfilename] 1<br/>[myfilename] 0<br/><br/>How can I eliminate those last 2 lines?<br/><br/>Thanks in advance<br/><br/><br/></blockquote> What is your whole code? Quote<blockquote>I am modifying the code and when I echo the results I get unwanted lines:<br/></blockquote> <br/>You may have modified the code to the point of breaking it. <br/><br/> Code: <a>[Select]</a>:laptop<br/>set localdrv=d:\workspaces<br/>for /f "skip=5" %%i in ('dir /tw %localdrv%\%plantid%\batch\gisdb\wad\%plantid%%wad%.dbf') do (<br/> echo %plantid%%wad%.dbf %%i Laptop<br/> goto getout<br/>) <br/>:getout<br/><br/>The <strong>for</strong> statement creates a loop. The <strong>skip</strong> parameter only skipped lines in the beginning of the directory list. The remaining lines after the one you want to process must be skipped manually.<br/><br/>Good luck. Quote from: Sidewinder on August 06, 2010, 12:09:55 PM<blockquote>You may have modified the code to the point of breaking it. <br/><br/> Code: <a>[Select]</a>:laptop<br/>set localdrv=d:\workspaces<br/>for /f "skip=5" %%i in ('dir /tw %localdrv%\%plantid%\batch\gisdb\wad\%plantid%%wad%.dbf') do (<br/> echo %plantid%%wad%.dbf %%i Laptop<br/> goto getout<br/>) <br/>:getout<br/><br/>The <strong>for</strong> statement creates a loop. The <strong>skip</strong> parameter only skipped lines in the beginning of the directory list. The remaining lines after the one you want to process must be skipped manually.<br/><br/>Good luck. <br/></blockquote> Thanks. It works like a charm!</body></html> | |