Kepping Directory Permissions

Tracy Tripp nwz at uwm.edu
Thu Nov 6 19:59:01 EST 2003


I'm working on a program that takes files by path and moves them into
new locations, and then back again if the user intends.  Everything is
great so far except I cannot figure out how to keep directory
permissions.  File permissions are no problem, but when I try and put
a directory's permissions back, I, the user, lose all access to that
directory.  When I give myself permission again, all my files have
kept their permissions.  Here are some functions I am working with:

I have a File object that keeps the files original path, its new path
and permissions.  When an instance is made of this object, it uses:
dirPath = os.path.dirname(filePath) to get the the files parent
directory.  I get the directories permissions with this data calling
os.stat(dirPath)[0] and saving this value into an integer essentially.
 When it comes time to move the file, I use os.renames() to put the
file into its new location, copy its permission's over and copy its
directories permissions over.  It works for the file, but not for the
directories.  Any ideas on how to save a directories permissions when
moved using renames()?  Thank you.

-Tracy Tripp




More information about the Python-list mailing list