<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://performiq.com/kb/index.php?action=history&amp;feed=atom&amp;title=Utilities_-_chmodr.py</id>
	<title>Utilities - chmodr.py - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://performiq.com/kb/index.php?action=history&amp;feed=atom&amp;title=Utilities_-_chmodr.py"/>
	<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=Utilities_-_chmodr.py&amp;action=history"/>
	<updated>2026-05-18T11:37:57Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.37.1</generator>
	<entry>
		<id>https://performiq.com/kb/index.php?title=Utilities_-_chmodr.py&amp;diff=4283&amp;oldid=prev</id>
		<title>PeterHarding: Created page with &quot;Change the mode of files and directories recursively from here to a useful value.  Used to fix my cygwin file permissions which keep getting reset to 0000   =Script=  &lt;pre&gt; $ ...&quot;</title>
		<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=Utilities_-_chmodr.py&amp;diff=4283&amp;oldid=prev"/>
		<updated>2014-09-09T07:36:26Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Change the mode of files and directories recursively from here to a useful value.  Used to fix my cygwin file permissions which keep getting reset to 0000   =Script=  &amp;lt;pre&amp;gt; $ ...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Change the mode of files and directories recursively from here to a useful value.  Used to fix my cygwin file permissions which keep getting reset to 0000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Script=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cat ~/bin/chmodr.py&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import os&lt;br /&gt;
import glob&lt;br /&gt;
&lt;br /&gt;
#--------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
executables = (&amp;#039;exe&amp;#039;, &amp;#039;py&amp;#039;, &amp;#039;rb&amp;#039;, &amp;#039;sh&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
#--------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
def chmod(dir):&lt;br /&gt;
&lt;br /&gt;
    os.chdir(dir)&lt;br /&gt;
&lt;br /&gt;
    print os.getcwd()&lt;br /&gt;
&lt;br /&gt;
    files = glob.glob(&amp;#039;*&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
    ordinary    = []&lt;br /&gt;
    directories = []&lt;br /&gt;
&lt;br /&gt;
    for file in files:&lt;br /&gt;
&lt;br /&gt;
        if os.path.isdir(file):&lt;br /&gt;
           directories.append(file)&lt;br /&gt;
        else:&lt;br /&gt;
           ordinary.append(file)&lt;br /&gt;
&lt;br /&gt;
    for file in ordinary:&lt;br /&gt;
        extension = os.path.splitext(file)[1][1:].lower()&lt;br /&gt;
        if (extension in executables):&lt;br /&gt;
            print &amp;quot;  Chmod executable file 0775 %s [%s]&amp;quot; % (file, extension)&lt;br /&gt;
            os.chmod(file, 0775)&lt;br /&gt;
        else:&lt;br /&gt;
            print &amp;quot;  Chmod file 0664 %s [%s]&amp;quot; % (file, extension)&lt;br /&gt;
            os.chmod(file, 0664)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    for directory in directories:&lt;br /&gt;
        os.chmod(directory, 0775)&lt;br /&gt;
        print &amp;quot;  Chmod dir 0775 %s&amp;quot; % directory&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    for directory in directories:&lt;br /&gt;
        chmod(directory)&lt;br /&gt;
&lt;br /&gt;
    os.chdir(&amp;#039;..&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
#--------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
chmod(&amp;#039;.&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
#--------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;br /&gt;
[[Category:Examples]]&lt;/div&gt;</summary>
		<author><name>PeterHarding</name></author>
	</entry>
</feed>