> On 08/19/2012 03:29 PM, Selby Rowley Cannon wrote:
>> OK, I have some code, and it uses glob.glob('*.py') to find all the
>> python files in the current directory.
>> Just thought i'd ask, would:
>>
>> glob.glob('C:\*.py') (Windows), or
>>
>> glob.glob('/*.py') (*nix)
>>
>> find all the python files on the system? Thanks
>
> See http://docs.python.org/library/glob.html
Selby,
Also there is no rule that says that all python files must end in .py.
Those that don't of course will not be 'found.' ;-(
I just happened to knock out a little script that might be easily adapted
to what you want to do. I'll attach it in case you want to make use of
it.
alex
>
> I don't see anywhere it implies that more than one directory would be
> scanned. In any case, it's pretty quick to just try it in the
> interpreter. I tried using python 2.7 on Linux, and it does not descend
> recursively into subdirectories.
>
> Perhaps you want os.walk, which lets you loop over an entire tree of
> files/directories.
>
> BTW, you forgot to double the backslash in your Windows example. Either
> double the backslash, or make it a raw string, or use forward slashes.
>
>
> --
>
> DaveA
>
>
> _______________________________________________
> Tutor maillist - [email protected]
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
#!/usr/bin/env python
import os.path
import os
import sys
def visitfunc(arg, dirname, names):
for name in names:
name_path = os.path.join(dirname, name)
if name[:2] == '._':
if os.path.isfile(name_path):
print "OK: %s"%(name_path, )
#os.remove(name_path)
# Delete the hash ('#') mark on the above line to "activate" this program.
# If you don't do that, the program is harmless; it simply tells you which
# files it would have deleted had you uncommented that line.
args = sys.argv[1:]
for argument in args:
print "AK: dir specified: '%s'"%(argument, )
arg_path = os.path.abspath(argument)
print "AK: path used: '%s'"%(arg_path, )
print "Unless the 'os.remove..' line is commented out,"
print "the following files will be deleted."
os.path.walk(arg_path, visitfunc, arg_path)
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor