Diff for "UtilityScripts" UserPreferences
 
Help Info Print View Search Diffs Edit
 À妽º   Ã£±â   Freeboard   Subjectless   Images   ÃÖ±Ù±Û 

Differences between version dated 2003-02-13 15:24:48 and 2024-11-23 09:05:40
Deletions are marked like this.
Additions are marked like this.

These are user-supplied utilities. If I like them, they will become part of the distribution. :)

 

Index: [[TableOfContents]]

 

== Remove all pages except the system pages ==

Provided by Engelbert Gruber <[email protected]>

{{{

#!/usr/bin/python

 

"""Delete all files not listed.

USAGE: rm-non-systempages SystemPages

  reads SystemPages and cleans curent directory"""

 

import sys,os

import re

 

if (len( sys.argv)<=2 ):

 print( __doc__ )

 sys.exit(0)

 

word_match = re.compile("^[ \*]*([^\s]+)")

# Read file list (survivors)

keep = {}

f = open(sys.argv[1])

 

while 1:

 line = f.readline()

 if not line:

  break

 m = word_match.match(line)

 if (m and len(m.group(1))>2):

  keep[m.group(1)] = 1

 

f.close()

 

# Scan through directory and remove files not in keep.

 

for entry in os.listdir(sys.argv[2]):

 # donot test for directories, remove wont do no harm.

 if (not keep.has_key(entry)):

  fn = os.path.join( sys.argv[2], entry )

  print "remove:"+fn

  os.remove( fn )

 else:

  print "keep:"+entry

}}}


PythonPowered ShowText of this page
EditText of this page
FindPage by browsing, searching, or an index
Or try one of these actions: DeletePage, DeleteUploadedFile, LikePages, SpellCheck, UploadFile