CMD file time not always matching windows explorer file time

07
2014-07
  • skyrail

    I have a set of file I need to set the created, modified and last access date to exif date taken value, after a copy between 2 folders (might be fat32 on memory card or ntfs on fixed or usb disk). When I copy a file, the date and time switch to the current date. Then I change all 3 dates manually, either with change attributes in windows explorer or far manager on the command line. To make it faster I wrote a batch script getting original file dates (with php and function stat), building a batch script that invoke nircmd setfiletime for each file. Then I apply this batch to the copied version.

    The operation is relatively fast and reliable. Unfortunately, a bunch of files have last access and created time different in cmd and windows explorer (1H difference). Very strangely, it happens with dates between november and february, which make the operation unreliable. Why is this happening, and how can I fix it?

  • Answers
    Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

    Related Question

    Windows Batch Scripting: Newest File Matching a Pattern
  • Eddie Parker

    This would be lightning quick in linux, but I'm not familiar enough with windows flavour of batch scripting.

    Basically I want to look for a series of files matching a certain wildcard, and get the one with the most recent modified date.

    I've gotten as far as:

    for %%X in (*.exe) do (
    REM Do stuff....
    )
    

    But I'm not sure what manner of comparison operators there are, or if there's a better way of doing this.

    Anyone offer up any good solutions? Ideally it would involve a vanilla install of Vista; so no special trickery like cygwin/etc.


  • Related Answers
  • njd

    There's almost certainly a more sane way to do this in PowerShell.
    But if it has to be cmd.exe:

    FOR /f %f IN ('DIR /b /od *.exe') DO @SET last=%f
    
    ECHO %last%
    

    DIR /b lists just the filename, like ls -1 would do; the /od is of course date order.
    So the last iteration sets the name of the last file in the list.

  • Eddie Parker

    Ah, found it:

    for /f %%x in ('dir *.exe /B /O:-D') do set NEWEST_EXE & goto DONE
    
    :DONE