0

There is more or less well-known command line way to update the modification time of a file on Windows (described at Update file or folder Date Modified, for example):

copy /b somePath\fileName+,, somePath\

According to my experience it does for a file, but does not for a directory (tested on WinXP - the command did not fail, but the directory modification time was not updated).

I tried to adjust it for a directory using such a trick that we can "point" to the directory using a special "NUL" filename on Windows. I tried two ways to do that, but they don't work as well:

copy /b somePath\fileName\NUL+,, somePath\filename\
copy /b somePath\fileName\NUL+,, somePath\

Could anyone explain me why it does not work or what I am doing wrong?

Alexander Samoylov
  • 2,358
  • 2
  • 25
  • 28
  • Which file system has the drive on which you used the copy command to update the last modification date of the folder? On all Windows the last modification date of a folder on NTFS partitions is updated if something is changed in the folder like creating a file and deleting it. But on FAT16 and FAT32 partitions the last modification date of a folder is not updated on something changes inside the folder. – Mofi Feb 22 '18 at 12:45
  • Yes, it was NTFS. – Alexander Samoylov Feb 22 '18 at 13:58

1 Answers1

0

It doesn't make any changes to the directory because the filename nul is not stored in the directory. Since the directory is not changed, its modification time doesn't change. You can do this instead:

type nul > somePath\fileName\SomeFileThatDoesNotExist.tmp && del somePath\fileName\SomeFileThatDoesNotExist.tmp
DodgyCodeException
  • 5,963
  • 3
  • 21
  • 42
  • So, there is no way to do it without a real modification of the directory content? The example you wrote above I know of course :) – Alexander Samoylov Feb 22 '18 at 13:56
  • 1
    @AlexanderSamoylov, I think this falls under the [KISS principle](https://en.wikipedia.org/wiki/KISS_principle). – Squashman Feb 22 '18 at 15:13
  • @Squashman yes, but I agree with Alexander: having to actually create a file and then delete it is not "simple". If it was possible to do the same as with a file (appending an empty file to an existing file updates its timestamp) then it would be simpler. Unfortunately, I don't know of a way to do that. – DodgyCodeException Feb 22 '18 at 15:17
  • IMHO, creating and deleting files is like an Introductory 101 class. You can't get much more simple than that. The hack used to touch a file wouldn't be considered simple in my book. – Squashman Feb 22 '18 at 15:34