The task that I'm trying to handle is to create a set of wrappers around WINAPI to handle various file modifications for files with deep paths in Windows.
Currently, I copy files using WINAPI call prefixed with "\\?\" as suggested here. After copying the file, I'm using the file time metadata (created, accessed, modified) from the original file and setting the time on the destination file. I'm having a problem when I try to apply this logic to a readonly file.
This is what I've attempted so far:
- Copy the file.
- Remove the ReadOnly flag from the destination using SetFileAttributes after calling GetFileAttributes.
- GetFileTime(original)
- SetFileTime(destination) (with original file times)
- Apply the readonly flag again.
The problem with this is that the file modified time gets updated after reapplying the readonly flag. Is there a way to do this perserving all the metadata?