Howto echo or get file timestamp (date) in command (cmd) .bat script

By neokrates, written on October 30, 2010

cmd bat   snippet

Rate it
  • 1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
Ad
Poll
  • Which tool is used for SCM/VCS in your enterprise?

    • Subversion (SVN) (50%, 7 Votes)
    • We use no SCM (43%, 6 Votes)
    • Mercurial (Hg) (7%, 1 Votes)
    • Git (0%, 0 Votes)
    • Bazaar (0%, 0 Votes)
    • CVS (0%, 0 Votes)
    • Other (0%, 0 Votes)

    Total Voters: 14

    Vote

    Loading ... Loading ...
Feeds:
  • bodytext bodytext bodytext
Most popular search terms:

Print timestamp:

for %%a in (myfile.txt) do echo %%~ta

 

Get timestamp:

for %%a in (myfile.txt) do set myfiledate=%%~ta

 
[i] To use the myfiledate inside the FOR loop you will probably need to enable delayed expansion (ENABLEDELAYEDEXPANSION), like:

@echo off
 
@SETLOCAL ENABLEDELAYEDEXPANSION
 
for %%a in (myfile.txt) do (
  set myfiledate=%%~ta
  echo !myfiledate!
)
 
Does that help to solve your problem?
VN:F [1.8.5_1061]
Rating: +4 (from 6 votes)
5 votes 'YES'  1 votes 'NO'
TAGS
RELATED
Pages
Posts
    nope :(
SOCIAL
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • BlinkList
  • Blogosphere News
  • E-mail this story to a friend!
  • Furl
  • LinkArena
  • Live
  • MisterWong
  • Print this article!
  • StumbleUpon
  • Technorati
  • Webnews.de
  • YahooMyWeb

Leave a Reply