How can I copy deep path readonly files and keep the file time metadata?
The challenge I'm trying to handle is to create a set of wrappers around WINAPI to handle various file modifications for deep path files on Windows.
I am currently copying files using a WINAPI call prefixed with "\\? \" As suggested here . After copying the file, I use the file time metadata (created, available, modified) from the source file and set the time in the target file. I have a problem when I try to apply this logic to a readonly file.
This is what I have tried to do so far:
- Copy the file.
- Remove the ReadOnly flag from the target using SetFileAttributes after calling GetFileAttributes.
- GetFileTime (original)
- SetFileTime (destination) (with original file time)
- Reapply the readonly flag.
The problem is that the changed file time is updated after reapplying the readonly flag. Is there a way to do this while keeping all the metadata?
+2
source to share