Changing file permission in Python

os.chmod(path, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) stat The following flags can also be used in the mode argument of os.chmod(): stat.S_ISUID Set UID bit. stat.S_ISGID Set-group-ID bit. This bit has several special uses. For a directory it indicates that BSD semantics is to be used for that directory: files created there inherit their group ID … Read more

How to grant permission to users for a directory using command line in Windows?

As of Vista, cacls is deprecated. Here’s the first couple of help lines: C:\>cacls NOTE: Cacls is now deprecated, please use Icacls. Displays or modifies access control lists (ACLs) of files You should use icacls instead. This is how you grant John full control over D:\test folder and all its subfolders: C:\>icacls “D:\test” /grant John:(OI)(CI)F … Read more

Retaining file permissions with Git

Git is Version Control System, created for software development, so from the whole set of modes and permissions it stores only executable bit (for ordinary files) and symlink bit. If you want to store full permissions, you need third party tool, like git-cache-meta (mentioned by VonC), or Metastore (used by etckeeper). Or you can use … Read more

Checking for directory and file write permissions in .NET

Directory.GetAccessControl(path) does what you are asking for. public static bool HasWritePermissionOnDir(string path) { var writeAllow = false; var writeDeny = false; var accessControlList = Directory.GetAccessControl(path); if (accessControlList == null) return false; var accessRules = accessControlList.GetAccessRules(true, true, typeof(System.Security.Principal.SecurityIdentifier)); if (accessRules ==null) return false; foreach (FileSystemAccessRule rule in accessRules) { if ((FileSystemRights.Write & rule.FileSystemRights) != FileSystemRights.Write) continue; … Read more