Update file or folder Date Modified

前端 未结 4 1685
无人共我
无人共我 2021-01-03 09:14

I need to update the \"Date Modified\" property of files and folders as they are copied from one location to the other so that \"Date Modified\" = Current System Time. I ha

相关标签:
4条回答
  • 2021-01-03 09:39
    for /R %i in (\*.\*) do copy %i /B+ ,,/Y
    
    0 讨论(0)
  • 2021-01-03 09:40

    Robocopy should be able to do this for you. robocopy is a native tool included in Windows since Vista.

    robocopy "\sharepoint\dept\gis\Abandoned_Wire" "\corp.dom\fs4\g1\OUTPUT\GRIDPROD\PDF\Maps\Abandon Wire Maps" /COPY:DA /S /IS
    

    By default robocopy will copy DAT: Data, Attributes, and the Time stamps, but this can be controlled with the /COPY flag.

    See robocopy /? for all the options.

    0 讨论(0)
  • 2021-01-03 09:45

    You could use powershell, which I believe is already installed on Windows 7 by default. Add this line to your batch file to run a powershell command that updates the timestamp on all files named Abandoned_Wire*.*:

    powershell.exe -command "ls 'folder\Abandoned_Wire\*.*' | foreach-object { $_.LastWriteTime = Get-Date }"
    

    What that line is doing is simply:

    -command: tells powershell to run the following command and return immediately

    ls: list all matching files at the path specified

    foreach-object: run the following block on each file that ls found

    $_.LastWriteTime = Get-Date: for each file, set the LastWriteTime to the value returned by Get-Date (today's date and time)

    0 讨论(0)
  • 2021-01-03 09:47

    There is a very simple (though arcane) syntax to "touch" a file on Windows. (update the last modified timestamp)

    If the file is in the current directory, all you need is:

    copy /b fileName+
    

    If the file is in some other path, then this works:

    copy /b somePath\fileName+,, somePath\
    

    However, it seems like you still would have a lot of coding to do, since I believe you only want to touch files that are copied.

    The following is untested, though I believe it will work. I can't vouch for the performance. This solution requires 2 unused drive letters. I'm assuming K: and L: are available.

    @echo off
    
    :: map unused drive letters to your source and target paths
    subst K: "\\sharepoint\dept\gis\Abandoned_Wire"
    subst L: "\\corp.dom\fs4\g1\OUTPUT\GRIDPROD\PDF\Maps\Abandon Wire Maps"
    
    :: replicate the folder hierarchy
    xcopy K: L: /t
    
    :: recursively copy and touch all files
    for /r K: %%F in (*) do (
      xcopy "%%F" "L:%%~pnxF" /r /y
      copy /b "L:%%~pnxF"+,, "L:%%~pF"
    )
    
    :: release the temporary drive mappings
    subst /d K:
    subst /d L:
    
    0 讨论(0)
提交回复
热议问题