Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update file or folder Date Modified

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 have a PC with Windows 7, and I do NOT have administrative rights on it, so I can't install any custom utilities. My current bat file uses XCOPY:

xcopy "\\sharepoint\dept\gis\Abandoned_Wire\*.*" "\\corp.dom\fs4\g1\OUTPUT\GRIDPROD\PDF\Maps\Abandon Wire Maps" /c /s /r /y /i

On my Windows XP box I use the "touch" command from UnxUtils, but I can't find an equivalent that's native to Windows 7. Thank you!

like image 282
Graeca Avatar asked Dec 15 '22 13:12

Graeca


1 Answers

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:
like image 84
dbenham Avatar answered Mar 01 '23 23:03

dbenham