How to copy a file on Windows while preserving permissions

A

Andrew Koenig

The answer to this question probably involves pywin32 or a similar library.

I would like to copy a file from one place to another on a Windows machine
while preserving as much of the file permissions as it is possible to
preserve with whatever my program's privileges happen to be. If the file is
a directory (i.e. folder), this might require temporarily granting myself
write permission for the directory so I can (recursively) create files in
it--again, assuming that it is possible to do so.

Obviously it would be necessary to determine whether my program's privileges
are sufficient to solve this problem for the particular files in question.

Can someone who is more familiar than I with the vagaries of Windows file
protection and the Python interfaces available to it point me in a useful
direction?
 
?

=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=

Can someone who is more familiar than I with the vagaries of Windows file
protection and the Python interfaces available to it point me in a useful
direction?

To copy a file along with its attributes, try SHFileOperation.

Alternatively, if you have backup privileges, open the file for backup,
then use BackupRead/BackupWrite.

HTH,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top