Created
September 1, 2012 11:18
-
-
Save danielpclark/3570204 to your computer and use it in GitHub Desktop.
Change all attributes to read write and execute for selected files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# App Name: attoff | |
# Version: 0.2 | |
# | |
# Author: Daniel P. Clark | |
# Date of creation: 06-05-2002 | |
# Last modified: 12-21-2004 | |
# | |
# E-mail: webmaster@6ftdan.com | |
import os, sys, fnmatch, string | |
FilePerm = 0777 | |
recursive = 0 | |
casesensitive = 1 | |
ROOTDIR = "." | |
WORDSEARCHL = [] | |
skip = 0 | |
FILESIZES = [] | |
print "AttOff - Version 0.2 - Stable 6ft Dan(TM)" | |
print "Copyright 2002 (c) All Rights Reserved" | |
print "---------------------------------------------" | |
for x in range(len(sys.argv)): | |
if x == 0: # don't add count to list | |
if len(sys.argv) == 1: | |
print "USAGE: attoff -r '*.mp3'" | |
elif string.lower(sys.argv[x]) == "-r": | |
recursive = 1 | |
elif string.lower(sys.argv[x])[:2] == "-d": | |
if len(sys.argv[x]) > 3: | |
ROOTDIR = sys.argv[x][3:] | |
else: | |
if len(sys.argv) > x: | |
ROOTDIR = sys.argv[x+1] | |
skip = 1 | |
elif string.lower(sys.argv[x]) == "-c": | |
casesensitive = 0 | |
elif string.lower(sys.argv[x]) in ("-h", "--help"): | |
print "HELP attoff 0.1" | |
print "-r\t\trecursive count" | |
print "-c\t\tdisable case sensitivity" | |
print "-d=dir\t\tset directory to initiate count in" | |
print "-h\t\tthis help message" | |
print "--help\t\tsame" | |
print "NOTE: In order for the program to return the results you'd like," | |
print "you may have to put your search strings in quotes! e.g '*.mp3'" | |
print "NOTE2: Linux FS Only" | |
sys.exit() | |
else: | |
if skip != 1: | |
WORDSEARCHL.append(sys.argv[x]) | |
else: | |
skip = 0 | |
if os.name in ("dos","os2","nt"): | |
casesesitive = 0 | |
def fileinfoist(PATTERN, DIR, FILES): | |
for y in FILES: | |
if os.path.isfile(DIR + os.sep + y): | |
if casesensitive: | |
if fnmatch.fnmatchcase(y, PATTERN): | |
FILESIZES.append(os.path.getsize(DIR + os.sep + y)) | |
os.chmod(DIR + os.sep + y, FilePerm) | |
else: | |
if fnmatch.fnmatch(string.lower(y), string.lower(PATTERN)): | |
FILESIZES.append(os.path.getsize(DIR + os.sep + y)) | |
os.chmod(DIR + os.sep + y, FilePerm) | |
for x in WORDSEARCHL: | |
FILESIZES = [] | |
if recursive: | |
os.path.walk(ROOTDIR, fileinfoist, x) | |
else: | |
fileinfoist(x, ROOTDIR, os.listdir(ROOTDIR)) | |
TSPACE = 0 | |
for z in FILESIZES: | |
TSPACE = TSPACE + z | |
if TSPACE != 0: | |
TOTALSPACE = str(round(TSPACE/1024))[:-2] + " Kb" | |
AVGSIZE = str(round(round(TSPACE/len(FILESIZES))/1024))[:-2] + " Kb" | |
FILECOUNT = len(FILESIZES) | |
print "Search Results For " + x | |
print "Total Files: " + str(FILECOUNT) + " Combined Size: " + TOTALSPACE + " Average Size: " + AVGSIZE | |
print "All Attributes Now With Read/Write/Excecute Permision." | |
else: | |
print "NO RESULTS WERE FOUND FOR " + x + "!" | |
print "---------------------------------------------" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment