Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Echo file date  (Read 3780 times)

0 Members and 1 Guest are viewing this topic.

anymouse

    Topic Starter


    Starter

    • Experience: Experienced
    • OS: Windows 7
    Echo file date
    « on: January 04, 2017, 11:10:31 AM »
    Modifying some code I found.  Basically I am parsing a directory and subdirectory filelist out after a date and writing the info to a text file to use as input into 7 zip.  I was going to use forfiles when I found out that one can not exclude directories when using -s.  My problem is echoing out the file date using echo %%~tF.  I get a blank line.  or with other variants I get the colon . I am missing something here.  I got stuck on the echo.

    Current version of code:

    @echo off
    for /D %%D in ("c:\Docs\*.*") do (
        if /I not "%%D"=="c:\docs\outlook data files" (
    ::store current directory
            pushd "%%D"
    ::recurse through directory for file
            for /R %%F in (%%D) do (
     
       echo ok
     echo :%%~tF
             
            )
            popd
        )
    )

    The version gives:

    ok
    :
    ok
    :

    Ultimately, I want to add an if to compare the file date to a date I specify and if >= echo file to the file list using something like : ECHO @PATH\@FILE>> "c:\test\ziplst.txt"

    Salmon Trout

    • Guest
    Re: Echo file date
    « Reply #1 on: January 04, 2017, 12:38:58 PM »
    Quick sanity check... you want to find a folder under C:\Docs, called "C:\Docs\outlook data files", (which WILL be present?) and then echo the date and time of every single file in that folder, preceding each date with a colon? Is that right?



    « Last Edit: January 04, 2017, 01:34:01 PM by Salmon Trout »

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: Echo file date
    « Reply #2 on: January 04, 2017, 06:24:55 PM »
    Please use code tags.

    anymouse

      Topic Starter


      Starter

      • Experience: Experienced
      • OS: Windows 7
      Re: Echo file date
      « Reply #3 on: January 05, 2017, 04:17:03 AM »
      I initially looked under Help and Posting for how to insert code before posting.  I looked for some other general stickies, couldn't find one though. Help had a lot of stuff on Polls, nothing on posting inline code in Posting.   Do you have a code tag format link?

      Search seemed to be dyfunctional.  Perhaps I do not understand how to use the Search.  I did a search on batch and date and one on just date, got nothing returned yet in just going through the forum pages found a couple of threads on batch and date.

      anymouse

        Topic Starter


        Starter

        • Experience: Experienced
        • OS: Windows 7
        Re: Echo file date
        « Reply #4 on: January 05, 2017, 04:24:50 AM »
        . you want to find a folder under C:\Docs, called "C:\Docs\outlook data files"

        C:\Docs\outlook data files   gets excluded from the search since there is a not in the compare.  %%D has current path & filename. 

        anymouse

          Topic Starter


          Starter

          • Experience: Experienced
          • OS: Windows 7
          Re: Echo file date
          « Reply #5 on: January 05, 2017, 08:47:57 AM »
          Started over and now have different problem.  FileDate var is getting set to last file's date in the Echo for all files.


          Code: [Select]
          for /R "C:\test\" %%D in (*.*) do (
          set FileDate=%%~tD
          ECHO %%D:  CurFDate: %%~tD:    %FileDate:~0,10%  >>I:\tem.txt

          )


          output:

          C:\test\t1.dat:  CurFDate: 10/15/2014 02:26 PM:    11/11/2014 
          C:\test\t2.dat:  CurFDate: 10/15/2014 02:34 PM:    11/11/2014 
          C:\test\t3.txt:  CurFDate: 11/16/2015 10:42 AM:    11/11/2014 
          C:\test\t4.txt:  CurFDate: 12/31/2015 08:53 AM:    11/11/2014 
          C:\test\t5.txt:  CurFDate: 05/11/2016 02:20 PM:    11/11/2014 
          C:\test\TestL2\t6subd.dat:  CurFDate: 11/11/2014 01:56 PM:    11/11/2014 

          Squashman



            Specialist
          • Thanked: 134
          • Experience: Experienced
          • OS: Other
          Re: Echo file date
          « Reply #6 on: January 09, 2017, 11:40:54 AM »
          Because you are not using delayed expansion.