By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,898 Members | 1,198 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,898 IT Pros & Developers. It's quick & easy.

file/directory format/size help

P: n/a
Hi

I am writing a script to upload images. How do I check the format of
the file? How can I tell if the file is an image, movie, or text file?
I would also like to put a limit on how much a user can upload. So how
can I check how many bits, bytes, mb, gb are in a folder.

So that sums up to

#1 What type of file is the file? Is it a movie, image, or text
document?
#2 What particular form is the file jpeg, bmp, gif etc.?
#3 The size of a directory?

Thanks

Dec 24 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Sun, 24 Dec 2006 07:45:32 -0800, moishyyehuda wrote:
Hi

I am writing a script to upload images. How do I check the format of
the file? How can I tell if the file is an image, movie, or text file?
I would also like to put a limit on how much a user can upload. So how
can I check how many bits, bytes, mb, gb are in a folder.

So that sums up to

#1 What type of file is the file? Is it a movie, image, or text
document?
In the Windows world, one simply looks at the file extension (e.g. .gif,
..avi, .txt, etc.) and hopes that it is correct.

In the Linux world, there is a command "file" that tries to guess the file
type, by looking at some combination of extension and/or signature bytes
inside the file.

Classic Macintosh OS kept file-type metadata as part of the file system; I
don't know what OS X based Macintoshes do.

Why do you care what the format of the file is? Can't you let the user
upload whatever file they like?

#2 What particular form is the file jpeg, bmp, gif etc.?
I don't understand the question. What do you mean "form"?

#3 The size of a directory?
Directories themselves generally are a fixed size, e.g. on my ext3 file
system my directories are typically 4K in size. But that's probably not
what you mean :-)

I assume you mean the size of all the files in a directory combined. You
have to get the size of each file, and add them all together. If you use
Google, you will find Python code to do that. Try looking on the
ActiveState Python Cookbook:

http://aspn.activestate.com/ASPN/Python/Cookbook/

--
Steven.

Dec 24 '06 #2

P: n/a
>#1 What type of file is the file? Is it a movie, image, or text
document?

In the Windows world, one simply looks at the file extension (e.g. .gif,
.avi, .txt, etc.) and hopes that it is correct.
or simply use TRID:
http://mark0.net/soft-trid-e.html

Stef Mientki
Dec 24 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.