1.

Solve : How to get the last modified date of a file into a textfile?

Answer»

Hi all,

I am very poor in writting batch files, but I want to get the last modified date of a file into a text file.

Could you please PROVIDE me the code for that.



THANKS in advance
SarayuThis may help:

Code: [Select]echo off
for /f "skip=5" %%x in ('dir /tw drive:\path\filename.extension') do (
  echo %%x > text.file
  goto :eof
)

Be sure to change drive:\path\filename.extension to SOMETHING appropriate.

Good luck.  Alternatively
Code: [Select]for /f %%T in ('dir /b filename.ext') do echo %%~tT>text.fileHi,

I am MODIFYING the code and when I echo the results I get unwanted lines:

:laptop
set localdrv=d:\workspaces
for /f "skip=5" %%i in ('dir /tw %localdrv%\%plantid%\batch\gisdb\wad\%plantid%%wad%.dbf') do (echo %plantid%%wad%.dbf %%i Laptop)

The mod date echoes correctly but I get 2 extra lines after the date is ECHOED
[myfilename] 1
[myfilename] 0

How can I eliminate those last 2 lines?

Thanks in advance

Quote from: mcgriff1969 on August 06, 2010, 09:19:23 AM

Hi,

I am modifying the code and when I echo the results I get unwanted lines:

:laptop
set localdrv=d:\workspaces
for /f "skip=5" %%i in ('dir /tw %localdrv%\%plantid%\batch\gisdb\wad\%plantid%%wad%.dbf') do (echo %plantid%%wad%.dbf %%i Laptop)

The mod date echoes correctly but I get 2 extra lines after the date is echoed
[myfilename] 1
[myfilename] 0

How can I eliminate those last 2 lines?

Thanks in advance


What is your whole code? Quote
I am modifying the code and when I echo the results I get unwanted lines:

You may have modified the code to the point of breaking it. 

Code: [Select]:laptop
set localdrv=d:\workspaces
for /f "skip=5" %%i in ('dir /tw %localdrv%\%plantid%\batch\gisdb\wad\%plantid%%wad%.dbf') do (
  echo %plantid%%wad%.dbf %%i Laptop
  goto getout
)
:getout

The for statement creates a loop. The skip 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.

Good luck.  Quote from: Sidewinder on August 06, 2010, 12:09:55 PM
You may have modified the code to the point of breaking it. 

Code: [Select]:laptop
set localdrv=d:\workspaces
for /f "skip=5" %%i in ('dir /tw %localdrv%\%plantid%\batch\gisdb\wad\%plantid%%wad%.dbf') do (
  echo %plantid%%wad%.dbf %%i Laptop
  goto getout
)
:getout

The for statement creates a loop. The skip 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.

Good luck. 
Thanks.  It works like a charm!


Discussion

No Comment Found