dealing with empty strings

this is a section of my code:

set emptyString to ""
if fileType = emptyString then
	display dialog "I don't recognize the file extension"
else
	display dialog fileType & " " & result
end if

Now, what I want is for the dialog boxes to work correctly, however when I identify a fileType it drops down to my else clause. Any input would be most appreciated.

Thanks,
Ian

You need to post more of your code.

Jon

I’m a little confused by your post. You say at the end that when you specify a fileType (e.g., fileType IS NOT emptyString) you’re script jumps down to your “else” clause.
Unless I’m reading something wrong, that’s exactly what your script is telling it to do. It’s evaluating fileType = emptyString to false and therefore moving to the “else” clause. If this isn’t what you’re expecting, then you may want to post a more detailed explanation or what exactly you’re trying to do.

Also, instead of setting an emptyString variable, you can just use “” in your script. It’s only two keys instead of 11.

Hope this helps.

choose file
copy the result to thisfile
copy the file type of the (info for thisfile) to fileType
set emptyString to "" 
if fileType = emptyString then 
   display dialog "I don't recognize the file extension" 
else 
   display dialog fileType & " " & result 
end if

Thats it, all it does is identify file type and path.

Keep in mind that most file types have a four character type definition, i.e. a .txt file is understood by the OS to be a TEXT file, a .app file is understood to be APPL. Now if, for instance you have a .csv file, the OS has no recognizable format for this file and the fileType returned is “”, or an empty string.

Got ya. The only thing I can think of is to have another else statement catch it if there’s no file type, and try to get the file’s extension, then somehow convert that to a file type (you’ll need some kind of list of extensions and corresponding file types to do this). Presumably, any file will have either a file type or extension (or you’d have to specify an app to open it each time).

Yeah, thats where my problem ls. I cant seem to get the script to acknowledge when fileType is empty. I also tried to set it to null if it was empty but still the condition was bypassed and it dropped into the else.

Sometimes a file type only looks empty but, in fact, contains invisible characters. Try this code (it’s got the invisible characters and, as such, can’t be posted to the board):

http://homepage.mac.com/jonn8/as/dist/get_file_type.sit

Jon

Thanks, that works beautifully :slight_smile: