Mine værktøjer
Du er her: Forside diverse filer til download mm. findfiler.py
Handlinger tilknyttet webside

findfiler.py

af Lars Bauer JørgensenSidst opdateret 01/07 2010 15:27

Find filer

Klik her for at hente fil

Størrelse: 2.6 kB - Filtype text/python-source

Indhold af fil-indholdsobjekt

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
u"""Usage: findfiler.py [-p <path>] [-s <suffix> ] [-S <IgnoresSuffix>] [-D <IgnoreDir>] 
    <path>: default to "." angiver søgnings startpunkt
    <IgnoresSuffix>: Suffix to ignore defaults to %(isuffix)s
    <suffix>: Suffix to find defaults to %(suffix)s
    <IgnoreDir>: dirs to ignore 
    Returns a list off filenames
"""
import sys
import os
import optparse
from os.path import isfile

def find(Path=".", onlySuffix=[], IgnoreSuffix=[], IgnoreDirs=[], vim="" ):
    """find [<path>] [<IgnoresSuffix>] [<IgnoreDir>]
        <path>: default to "." angiver søgnings startpunkt
        <onlySuffix>    : only this suffix
        <IgnoresSuffix> : Sufix to ignore defalt to []
        <IgnoreDir>     : dirs to ignore defalt to []
        <vim>           : drop files ending with this string
        Returns a list off filenames ignoring pipes.
    """
    Foundnames = []
    for dirpath, dirnames, filenames in os.walk( Path ):
        Idirs = [ Dir for Dir in dirpath.split("/") if Dir in IgnoreDirs ]
        if Idirs:
            continue
        for fname in ["%s/%s" % (dirpath, fname ) for fname in filenames]:
            if not isfile( fname ):
                continue
            suffix=fname.split(".")[-1] 
            if vim and fname.endswith(vim): continue
            if onlySuffix:
                if suffix not in onlySuffix:
                    continue
            elif suffix in IgnoreSuffix:
                continue
            yield "%(fname)s" % vars()


if __name__ == "__main__":

    suffix = []
    isuffix = []
    P = optparse.OptionParser(usage=__doc__ % vars())

    P.add_option("-p","--path",
                 help="path to where the search begins",
                 action="store",
                 default="." )

    P.add_option("-s","--suffix",
                 help="files ending with suffix",
                 action="append",
                 default=suffix)

    P.add_option("-t","--test",
                 help="start pdb, hackers choice",
                 action="store_true",
                 default=False)

    P.add_option("-i","--isuffix",
                 help="ignore files ending with suffix",
                 action="append",
                 default = isuffix)

    P.add_option("-d","--dirs",
                 help="ignore dirs",
                 action="store_true",
                 default=[])

    (optlist, args) = P.parse_args(sys.argv[1:])

    if  optlist.test:
        import pdb;pdb.set_trace()

    print " ".join(find(Path=optlist.path, onlySuffix=optlist.suffix, IgnoreSuffix=optlist.isuffix, IgnoreDirs=optlist.dirs))
« august 2018 »
søn man tir ons tor fre lør
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Chat Rooms
Dyrk motion

Trim ballerup

 

Powered by Plone, the Open Source Content Management System