Search for AVI file?

Peter Hansen peter at engcorp.com
Mon Aug 30 16:15:44 EDT 2004


John Doe wrote:

> I realise that this is not really a python question, but python's the
> only language I'd be comfortable trying to deal with this.
> 
> What I need is to search a drive and find all the AVI format files
> that are NOT listed with the AVI extension.  I'm looking over an old
> drive of mine from an old computer.  I know the files were renamed
> with the wrong extension, but I know that they were originally AVI
> files.  Can python do this for me?  Any hints?  Anybody have a link to
> something that would already do this?  I appreciate any help.

Have you looked for and found information about the AVI file
format?  Google can help you with that.

You should easily be able to use Python to read the first
X bytes of a given file and check the signature to see if
it's likely an AVI file.  I'm sure there are exceptions
and new versions and such things, but if you have only
a bunch of "old" AVI files, it's quite possible they are
all detectable by doing something like checking that
bytes 0 through 3 are 'RIFF' and bytes 8 through 10 are
'AVI' (that info from a few handy sites on the AVI format).

Basically you could just open the file and do a .read(10)
and compare the result using slices, e.g. data[0:4] == 'RIFF'
and data[8:11] == 'AVI'.

-Peter



More information about the Python-list mailing list