determine file type

Mark Gibson mark at gibsonsoftware.com
Sun Mar 26 21:52:32 EST 2006


> 
> 
> import os
> def test_file(filename, maxread=1024):
>    if os.path.isdir(filename):
>      return 'directory'
>    afile = open(filename) # open as text
>    for achar in afile.read(maxread):
>      if ord(achar) > 127:
>        return 'binary'
>    return 'text'
> 
> 

Pefect, thanks!




More information about the Python-list mailing list