determine file type

Mark Gibson mark at gibsonsoftware.com
Mon Mar 27 04:52:32 CEST 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