On Fri, 16 Jan 2004, Jan Eden wrote:

> 
> >
> >if (`file $file` =~ /JPEG/) {
> >   print "$file appears to be a JPEG file.\n";
> >} else {
> >   print "$file does not appear to be a JPEG file.\n";
> >}
> >
> This will tell you if the filename contains a certain string. That does 
> not make the file a valid image file (besides, there's .jpg and .jpeg, 
> both in uppercase and lowercase, so your pattern should be:
> 
> /jpe?g/i
> 
> if you just want to check the name.
> 
> - Jan
> 

Not true in UNIX. Maybe in Windows, I don't know. Please notice the 
"backticks" which execute the "file" command. The "file" command in Linux 
examines the file in the command line and sends a single line indicating 
its opinion of what type of file the specified file is. It actually reads 
the file looking for "markers" of some sort. If the file is a JPEG file, 
then the response from the "file" command will contain the string JPEG (in 
upper case), which is what I test for.

This only works, as best as I know, on a UNIX system. Windows doesn't have 
this command, or it works differently. I don't do Windows.

-- 
--
Maranatha!
John McKown


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to