Getting the type code of a file under OSX

classic Classic list List threaded Threaded
25 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Getting the type code of a file under OSX

Howard Bornstein
I wanted to check to see if I'm missing something obvious. I want to
be able to get the type code of a specific file under OSX. As far as
I've been able to find, there is only one way to get the type code--
with the files function. The detailed files includes the type and
creator codes. However, this gets the entire list of files in the
default folder. Unless there's something I'm missing, the sequence
would be something like this:

1) Get the full path of the file you want the type code for
2) Extract the folder it's in
3) Set the default folder to that folder
4) Get the detailed files
5) Compare the file name with item one of every line in the files
6) When you find a match, extract the last item from the detailed file
description which is the type/creator code.

This seems like a lot of work, just to get an attribute of a file. We
have the filetype property, where we can set the type of a file. Isn't
there a simple way to *get* the type of a file?

--
Regards,

Howard Bornstein
-----------------------
www.designeq.com
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Getting the type code of a file under OSX

Eric Chatonet
Hi Howard,

You could use AppleScript but doing this with Transcript is easy and  
fast:

function CreatorAndType pFilePath
   local tDefaultFolder,tCreatorType
   -----
   if the platform <> "MacOs" then return "Error: filetype not  
supported"
   put the defaultFolder into tDefaultFolder
   set the itemdel to slash
   set the defaultFolder to item 1 to -2 of pFilePath
   put urlDecode(the detailed files) into tFiles
   put line lineOffset(item - 1 of pFilePath,tFiles) of tFiles into  
tFile
   set the defaultFolder to tDefaultFolder
   set the itemDel to comma
   put item 11 of tFile into tCreatorType
   if tCreatorType = empty then return "Error: could not find the  
filetype"
   return char 1 to 4 of item 11 of tFile & comma & char 5 to 8 of  
item -1 of tFile
   -- creator and type separated by a comma
end CreatorAndType

Best Regards from Paris,

Eric Chatonet.

Le 30 juil. 05 à 01:56, Howard Bornstein a écrit :

> I wanted to check to see if I'm missing something obvious. I want to
> be able to get the type code of a specific file under OSX. As far as
> I've been able to find, there is only one way to get the type code--
> with the files function. The detailed files includes the type and
> creator codes. However, this gets the entire list of files in the
> default folder. Unless there's something I'm missing, the sequence
> would be something like this:
>
> 1) Get the full path of the file you want the type code for
> 2) Extract the folder it's in
> 3) Set the default folder to that folder
> 4) Get the detailed files
> 5) Compare the file name with item one of every line in the files
> 6) When you find a match, extract the last item from the detailed file
> description which is the type/creator code.
>
> This seems like a lot of work, just to get an attribute of a file. We
> have the filetype property, where we can set the type of a file. Isn't
> there a simple way to *get* the type of a file?

----------------------------------------------------------------
So Smart Software

For institutions, companies and associations
Built-to-order applications: management, multimedia, internet, etc.
Windows, Mac OS and Linux... With the French touch

Free plugins and tutorials on my website
----------------------------------------------------------------
Web site        http://www.sosmartsoftware.com/
Email        [hidden email]/
Phone        33 (0)1 43 31 77 62
Mobile        33 (0)6 20 74 50 86
----------------------------------------------------------------

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Getting the type code of a file under OSX

Brian Yennie
Quick observation... you may get unreliable results when the name of
one file is a substring of the name of another file in the same folder.
You might try adding a comma to the file name, or using itemOffset()
and wholeMatches.

HTH
- Brian

> Hi Howard,
>
> You could use AppleScript but doing this with Transcript is easy and
> fast:
>
> function CreatorAndType pFilePath
>   local tDefaultFolder,tCreatorType
>   -----
>   if the platform <> "MacOs" then return "Error: filetype not
> supported"
>   put the defaultFolder into tDefaultFolder
>   set the itemdel to slash
>   set the defaultFolder to item 1 to -2 of pFilePath
>   put urlDecode(the detailed files) into tFiles
>   put line lineOffset(item - 1 of pFilePath,tFiles) of tFiles into
> tFile
>   set the defaultFolder to tDefaultFolder
>   set the itemDel to comma
>   put item 11 of tFile into tCreatorType
>   if tCreatorType = empty then return "Error: could not find the
> filetype"
>   return char 1 to 4 of item 11 of tFile & comma & char 5 to 8 of item
> -1 of tFile
>   -- creator and type separated by a comma
> end CreatorAndType
>
> Best Regards from Paris,
>
> Eric Chatonet.
>
> Le 30 juil. 05 à 01:56, Howard Bornstein a écrit :
>
>> I wanted to check to see if I'm missing something obvious. I want to
>> be able to get the type code of a specific file under OSX. As far as
>> I've been able to find, there is only one way to get the type code--
>> with the files function. The detailed files includes the type and
>> creator codes. However, this gets the entire list of files in the
>> default folder. Unless there's something I'm missing, the sequence
>> would be something like this:
>>
>> 1) Get the full path of the file you want the type code for
>> 2) Extract the folder it's in
>> 3) Set the default folder to that folder
>> 4) Get the detailed files
>> 5) Compare the file name with item one of every line in the files
>> 6) When you find a match, extract the last item from the detailed file
>> description which is the type/creator code.
>>
>> This seems like a lot of work, just to get an attribute of a file. We
>> have the filetype property, where we can set the type of a file. Isn't
>> there a simple way to *get* the type of a file?
>
> ----------------------------------------------------------------
> So Smart Software
>
> For institutions, companies and associations
> Built-to-order applications: management, multimedia, internet, etc.
> Windows, Mac OS and Linux... With the French touch
>
> Free plugins and tutorials on my website
> ----------------------------------------------------------------
> Web site        http://www.sosmartsoftware.com/
> Email        [hidden email]/
> Phone        33 (0)1 43 31 77 62
> Mobile        33 (0)6 20 74 50 86
> ----------------------------------------------------------------
>
> _______________________________________________
> use-revolution mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
>

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Getting the type code of a file under OSX

Eric Chatonet
Hi Brian,

As the files function returns a list sorted by alphabetical order, I  
don't think it's necessary.

Le 30 juil. 05 à 11:35, Brian Yennie a écrit :

> Quick observation... you may get unreliable results when the name  
> of one file is a substring of the name of another file in the same  
> folder. You might try adding a comma to the file name, or using  
> itemOffset() and wholeMatches.
>
> HTH
> - Brian
>
>
>> Hi Howard,
>>
>> You could use AppleScript but doing this with Transcript is easy  
>> and fast:
>>
>> function CreatorAndType pFilePath
>>   local tDefaultFolder,tCreatorType
>>   -----
>>   if the platform <> "MacOs" then return "Error: filetype not  
>> supported"
>>   put the defaultFolder into tDefaultFolder
>>   set the itemdel to slash
>>   set the defaultFolder to item 1 to -2 of pFilePath
>>   put urlDecode(the detailed files) into tFiles
>>   put line lineOffset(item - 1 of pFilePath,tFiles) of tFiles into  
>> tFile
>>   set the defaultFolder to tDefaultFolder
>>   set the itemDel to comma
>>   put item 11 of tFile into tCreatorType
>>   if tCreatorType = empty then return "Error: could not find the  
>> filetype"
>>   return char 1 to 4 of item 11 of tFile & comma & char 5 to 8 of  
>> item -1 of tFile
>>   -- creator and type separated by a comma
>> end CreatorAndType
>>
>> Best Regards from Paris,
>>
>> Eric Chatonet.
>>
>> Le 30 juil. 05 à 01:56, Howard Bornstein a écrit :
>>
>>
>>> I wanted to check to see if I'm missing something obvious. I want to
>>> be able to get the type code of a specific file under OSX. As far as
>>> I've been able to find, there is only one way to get the type code--
>>> with the files function. The detailed files includes the type and
>>> creator codes. However, this gets the entire list of files in the
>>> default folder. Unless there's something I'm missing, the sequence
>>> would be something like this:
>>>
>>> 1) Get the full path of the file you want the type code for
>>> 2) Extract the folder it's in
>>> 3) Set the default folder to that folder
>>> 4) Get the detailed files
>>> 5) Compare the file name with item one of every line in the files
>>> 6) When you find a match, extract the last item from the detailed  
>>> file
>>> description which is the type/creator code.
>>>
>>> This seems like a lot of work, just to get an attribute of a  
>>> file. We
>>> have the filetype property, where we can set the type of a file.  
>>> Isn't
>>> there a simple way to *get* the type of a file?
>>>
>>
>> ----------------------------------------------------------------
>> So Smart Software
>>
>> For institutions, companies and associations
>> Built-to-order applications: management, multimedia, internet, etc.
>> Windows, Mac OS and Linux... With the French touch
>>
>> Free plugins and tutorials on my website
>> ----------------------------------------------------------------
>> Web site        http://www.sosmartsoftware.com/
>> Email        [hidden email]/
>> Phone        33 (0)1 43 31 77 62
>> Mobile        33 (0)6 20 74 50 86
>> ----------------------------------------------------------------
>>
>> _______________________________________________
>> use-revolution mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your  
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>
>>
>>
>
> _______________________________________________
> use-revolution mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
>

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Getting the type code of a file under OSX

Dave Cragg

On 30 Jul 2005, at 10:40, Eric Chatonet wrote:

> Hi Brian,
>
> As the files function returns a list sorted by alphabetical order,  
> I don't think it's necessary.


But, for example, if you were looking for a file named "mend.png" and  
there was a file named "amend.png" in the folder, you'd find  
"amend.png".

A bit cumbersome, but when I've done this, I've repeated through all  
lines in the detailed files and done a match on the first item in each.

Cheers
dave


>
> Le 30 juil. 05 à 11:35, Brian Yennie a écrit :
>
>
>> Quick observation... you may get unreliable results when the name  
>> of one file is a substring of the name of another file in the same  
>> folder. You might try adding a comma to the file name, or using  
>> itemOffset() and wholeMatches.
>>
>> HTH
>> - Brian
>>
>>
>>
>>> Hi Howard,
>>>
>>> You could use AppleScript but doing this with Transcript is easy  
>>> and fast:
>>>
>>> function CreatorAndType pFilePath
>>>   local tDefaultFolder,tCreatorType
>>>   -----
>>>   if the platform <> "MacOs" then return "Error: filetype not  
>>> supported"
>>>   put the defaultFolder into tDefaultFolder
>>>   set the itemdel to slash
>>>   set the defaultFolder to item 1 to -2 of pFilePath
>>>   put urlDecode(the detailed files) into tFiles
>>>   put line lineOffset(item - 1 of pFilePath,tFiles) of tFiles  
>>> into tFile
>>>   set the defaultFolder to tDefaultFolder
>>>   set the itemDel to comma
>>>   put item 11 of tFile into tCreatorType
>>>   if tCreatorType = empty then return "Error: could not find the  
>>> filetype"
>>>   return char 1 to 4 of item 11 of tFile & comma & char 5 to 8 of  
>>> item -1 of tFile
>>>   -- creator and type separated by a comma
>>> end CreatorAndType
>>>
>>> Best Regards from Paris,
>>>
>>> Eric Chatonet.
>>>
>>> Le 30 juil. 05 à 01:56, Howard Bornstein a écrit :
>>>
>>>
>>>
>>>> I wanted to check to see if I'm missing something obvious. I  
>>>> want to
>>>> be able to get the type code of a specific file under OSX. As  
>>>> far as
>>>> I've been able to find, there is only one way to get the type  
>>>> code--
>>>> with the files function. The detailed files includes the type and
>>>> creator codes. However, this gets the entire list of files in the
>>>> default folder. Unless there's something I'm missing, the sequence
>>>> would be something like this:
>>>>
>>>> 1) Get the full path of the file you want the type code for
>>>> 2) Extract the folder it's in
>>>> 3) Set the default folder to that folder
>>>> 4) Get the detailed files
>>>> 5) Compare the file name with item one of every line in the files
>>>> 6) When you find a match, extract the last item from the  
>>>> detailed file
>>>> description which is the type/creator code.
>>>>
>>>> This seems like a lot of work, just to get an attribute of a  
>>>> file. We
>>>> have the filetype property, where we can set the type of a file.  
>>>> Isn't
>>>> there a simple way to *get* the type of a file?
>>>>
>>>>
>>>
>>> ----------------------------------------------------------------
>>> So Smart Software
>>>
>>> For institutions, companies and associations
>>> Built-to-order applications: management, multimedia, internet, etc.
>>> Windows, Mac OS and Linux... With the French touch
>>>
>>> Free plugins and tutorials on my website
>>> ----------------------------------------------------------------
>>> Web site        http://www.sosmartsoftware.com/
>>> Email        [hidden email]/
>>> Phone        33 (0)1 43 31 77 62
>>> Mobile        33 (0)6 20 74 50 86
>>> ----------------------------------------------------------------
>>>
>>> _______________________________________________
>>> use-revolution mailing list
>>> [hidden email]
>>> Please visit this url to subscribe, unsubscribe and manage your  
>>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>>
>>>
>>>
>>>
>>
>> _______________________________________________
>> use-revolution mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your  
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>
>>
>>
>
> _______________________________________________
> use-revolution mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Getting the type code of a file under OSX

Eric Chatonet
Hi Dave,

You are perfectly right: I missed this one.
So a reliable function could be:

function CreatorAndType pFilePath
   local tDefaultFolder,tFile,tCreatorType
   -----
   if the platform <> "MacOs" then return "Error: filetype not  
supported"
   put the defaultFolder into tDefaultFolder
   set the itemdel to slash
   set the defaultFolder to item 1 to -2 of pFilePath
   put urlDecode(the detailed files) into tFile
   filter tFile with item - 1 of pFilePath & ",*"
   if tFile = empty then return "Error: could not find file"
   set the defaultFolder to tDefaultFolder
   set the itemDel to comma
   put item 11 of tFile into tCreatorType
   if tCreatorType = empty then return "Error: could not find the  
filetype"
   return char 1 to 4 of item 11 of tFile & comma & char 5 to 8 of  
item -1 of tFile
end CreatorAndType


Le 30 juil. 05 à 13:07, Dave Cragg a écrit :

> On 30 Jul 2005, at 10:40, Eric Chatonet wrote:
>
>
>> Hi Brian,
>>
>> As the files function returns a list sorted by alphabetical order,  
>> I don't think it's necessary.
>>
>
>
> But, for example, if you were looking for a file named "mend.png"  
> and there was a file named "amend.png" in the folder, you'd find  
> "amend.png".
>
> A bit cumbersome, but when I've done this, I've repeated through  
> all lines in the detailed files and done a match on the first item  
> in each.
>
> Cheers
> dave


Best Regards from Paris,

Eric Chatonet.
----------------------------------------------------------------
So Smart Software

For institutions, companies and associations
Built-to-order applications: management, multimedia, internet, etc.
Windows, Mac OS and Linux... With the French touch

Free plugins and tutorials on my website
----------------------------------------------------------------
Web site        http://www.sosmartsoftware.com/
Email        [hidden email]/
Phone        33 (0)1 43 31 77 62
Mobile        33 (0)6 20 74 50 86
----------------------------------------------------------------

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Getting the type code of a file under OSX

Eric Chatonet
Last one was not perfect since the default folder is not restored  
when an error occurs:
Just invert  "if tFile = empty then return "Error: could not find  
file" and "set the defaultFolder to tDefaultFolder" lines.
Is this one the last one?
:-)

Best Regards from Paris,

Eric Chatonet.

Le 30 juil. 05 à 13:19, Eric Chatonet a écrit :

> Hi Dave,
>
> You are perfectly right: I missed this one.
> So a reliable function could be:
>
> function CreatorAndType pFilePath
>   local tDefaultFolder,tFile,tCreatorType
>   -----
>   if the platform <> "MacOs" then return "Error: filetype not  
> supported"
>   put the defaultFolder into tDefaultFolder
>   set the itemdel to slash
>   set the defaultFolder to item 1 to -2 of pFilePath
>   put urlDecode(the detailed files) into tFile
>   filter tFile with item - 1 of pFilePath & ",*"
>   if tFile = empty then return "Error: could not find file"
>   set the defaultFolder to tDefaultFolder
>   set the itemDel to comma
>   put item 11 of tFile into tCreatorType
>   if tCreatorType = empty then return "Error: could not find the  
> filetype"
>   return char 1 to 4 of item 11 of tFile & comma & char 5 to 8 of  
> item -1 of tFile
> end CreatorAndType
>
>
> Le 30 juil. 05 à 13:07, Dave Cragg a écrit :
>
>
>> On 30 Jul 2005, at 10:40, Eric Chatonet wrote:
>>
>>
>>
>>> Hi Brian,
>>>
>>> As the files function returns a list sorted by alphabetical  
>>> order, I don't think it's necessary.
>>>
>>>
>>
>>
>> But, for example, if you were looking for a file named "mend.png"  
>> and there was a file named "amend.png" in the folder, you'd find  
>> "amend.png".
>>
>> A bit cumbersome, but when I've done this, I've repeated through  
>> all lines in the detailed files and done a match on the first item  
>> in each.
>>
>> Cheers
>> dave


----------------------------------------------------------------
So Smart Software

For institutions, companies and associations
Built-to-order applications: management, multimedia, internet, etc.
Windows, Mac OS and Linux... With the French touch

Free plugins and tutorials on my website
----------------------------------------------------------------
Web site        http://www.sosmartsoftware.com/
Email        [hidden email]/
Phone        33 (0)1 43 31 77 62
Mobile        33 (0)6 20 74 50 86
----------------------------------------------------------------

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Getting the type code of a file under OSX

Dave Cragg

On 30 Jul 2005, at 13:02, Eric Chatonet wrote:

> Last one was not perfect since the default folder is not restored  
> when an error occurs:
> Just invert  "if tFile = empty then return "Error: could not find  
> file" and "set the defaultFolder to tDefaultFolder" lines.
> Is this one the last one?

Looks good here. I like the use of the filter command. I should get  
"filter" tattooed on the back of my hand as I have a habit of  
forgetting how useful it can be.

Cheers
Dave
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Getting the type code of a file under OSX

Alex Tweedly
In reply to this post by Eric Chatonet
Eric Chatonet wrote:

> Hi Dave,
>
> You are perfectly right: I missed this one.
> So a reliable function could be:
>
getting close ... but not quite there yet, because of the issue of comma
being an allowed character in file names.
(I don't know if this applies to Mac - but I'm 99% sure it will, since
this is a relatively common thing to do in Unix, so I'd expect the OSX
file system to allow it).

If the Mac doesn't allow this, then your function is OK - but beware of
the problem for any other operation you do on "the detailed files".

If Mac does allow commas in file names, then it causes two problems.

The first is easy - but rather dangerous. You cannot use "item 11" for
the file creator - you should alway use "item -1". The same applies to
all the items returned - you should use "item -10" for file size, rather
than "item 2", etc.

However, this doesn't work as it should on Windows.
The docs say

>     * The file's access permissions
>     * The file's creator and file type (Mac OS and OS X only)
> Any attribute that is not supported on the current system is reported
> as "0" (zero).
>
But in fact on Windows, the creator and file type (not supported) are
set to empty, not "0".
This is a real pain, because it means that you always have an empty last
item - so the number of items is 10.
[Does the Mac ever return empty Creator and file type ?]

Therefore you need to add a check for the last character being comma,
and if it is append some safe string (e.g. a space), before using the
negative index numbers.

The second problem is rather more obscure - but if we want to claim to
work in 100% of the cases, not 99.99..% we should cover it.

I believe you cannot use a "filter" to match any arbitrary filename you
might be given.

filter ... pFileName & ",*"
  fails because    "name" and "name,date" both match pFileName = "name"
You might think you could depend on the fact that the files are
alphabetic to always get the one you want first (I certainly did when I
started writing this email), but you can't.  Using the filename "a,11"
will falsely match the file "a" if it happens to be 11 bytes long (or
110, or 11234, ...). Since "a" comes before "a,11" it will be the first
one found.

You could try (I did !!) using the trick I saw from Richard a couple of
weeks ago, using a complex filter expression to ensure the right number
of items - e.g.
   filter ... pFileName & ",*,*,*,*,*,*,*,*,*,*"  
but that also fails the "a,11" case as above.

So I think you need to loop through them, checking the file name. But
you cannot do as Dave suggested, and compare item 1 of each line against
the file name, because that would fail to match a filename containing a
comma that should match.
You instead need to compare "item 1 to -11"  (once you've done the above
check for empty last item).

So we finish up with what I *think* is a truly reliable version

function CreatorAndType pFilePath
  local tDefaultFolder,tFile,tCreatorType, theLine, L, tNewFiles, tName
  -----
  if the platform <> "MacOs" then return "Error: filetype not  supported"
  put the defaultFolder into tDefaultFolder
  set the itemdel to slash
  set the defaultFolder to item 1 to -2 of pFilePath
  put urlDecode(the detailed files) into tFile
  put empty into tNewFiles
  put item -1 of pFilePath into tName
  set the itemDel to comma
  repeat for each line L in tFile
    put L into theLine
    if the last char of theLine = comma then put space after theLine
    if item 1 to -11 of theLine = tName then put L & cr after tNewFiles
  end repeat
  put tNewFiles into tFile
  -- put tFile & cr after msg
  if tFile = empty then return "Error: could not find file"
  set the defaultFolder to tDefaultFolder
  return tFile
 
end CreatorAndType


> Le 30 juil. 05 à 13:07, Dave Cragg a écrit :
>
>> On 30 Jul 2005, at 10:40, Eric Chatonet wrote:
>>
>>
>>> Hi Brian,
>>>
>>> As the files function returns a list sorted by alphabetical order,  
>>> I don't think it's necessary.
>>>
>>
>>
>> But, for example, if you were looking for a file named "mend.png"  
>> and there was a file named "amend.png" in the folder, you'd find  
>> "amend.png".
>>
>> A bit cumbersome, but when I've done this, I've repeated through  all
>> lines in the detailed files and done a match on the first item  in each.
>>
>> Cheers
>> dave
>
>
>
> Best Regards from Paris,
>
> Eric Chatonet.
> ----------------------------------------------------------------
> So Smart Software
>
> For institutions, companies and associations
> Built-to-order applications: management, multimedia, internet, etc.
> Windows, Mac OS and Linux... With the French touch
>
> Free plugins and tutorials on my website
> ----------------------------------------------------------------
> Web site        http://www.sosmartsoftware.com/
> Email        [hidden email]/
> Phone        33 (0)1 43 31 77 62
> Mobile        33 (0)6 20 74 50 86
> ----------------------------------------------------------------
>
> _______________________________________________
> use-revolution mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
>


--
Alex Tweedly       http://www.tweedly.net



--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.338 / Virus Database: 267.9.6/59 - Release Date: 27/07/2005

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Getting the type code of a file under OSX

Richard Gaskin
Alex Tweedly wrote:
> You could try (I did !!) using the trick I saw from Richard a couple of
> weeks ago, using a complex filter expression to ensure the right number
> of items - e.g.
>   filter ... pFileName & ",*,*,*,*,*,*,*,*,*,*"  but that also fails the
> "a,11" case as above.

For grabbing just one line I often just include boundaries around the
text with lineOffset:

   put lineoffset(cr& tMyFileame&"," , cr& tFileList)

Because the file names are URL encoded commas become %2C, so I don't
believe there's a risk of getting commas in the name confused with
delimiters.

--
  Richard Gaskin
  Managing Editor, revJournal
  _______________________________________________________
  Rev tips, tutorials and more: http://www.revJournal.com
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Getting the type code of a file under OSX

Eric Chatonet
In reply to this post by Alex Tweedly
Hi Alex,

I should not have thought that such a tiny problem could go so far :-)
Error management is the key of good software...
So, I propose another approach:
As usual, is this one the last one?
:-)

function CreatorAndType pFilePath
   local tDefaultFolder,tFile,tCreatorType
   -----
   if the platform <> "MacOs" then return "Error: filetype not  
supported"
   put the defaultFolder into tDefaultFolder
   set the itemdel to slash
   set the defaultFolder to item 1 to -2 of pFilePath
   put the detailed files into tFile
   filter tFile with urlEncode(item -1 of pFilePath) & ",*"
   set the defaultFolder to tDefaultFolder
   set the itemDel to comma
   if last char of tFile = comma then return "Error: could not  
determine the filetype"
   return char 1 to 4 of item -1 of tFile,char 5 to 8 of item -1 of  
tFile
end CreatorAndType

Le 30 juil. 05 à 15:06, Alex Tweedly a écrit :

> Eric Chatonet wrote:
>
>
>> Hi Dave,
>>
>> You are perfectly right: I missed this one.
>> So a reliable function could be:
>>
>>
> getting close ... but not quite there yet, because of the issue of  
> comma being an allowed character in file names.
> (I don't know if this applies to Mac - but I'm 99% sure it will,  
> since this is a relatively common thing to do in Unix, so I'd  
> expect the OSX file system to allow it).
>
> If the Mac doesn't allow this, then your function is OK - but  
> beware of the problem for any other operation you do on "the  
> detailed files".
> If Mac does allow commas in file names, then it causes two problems.
>
> The first is easy - but rather dangerous. You cannot use "item 11"  
> for the file creator - you should alway use "item -1". The same  
> applies to all the items returned - you should use "item -10" for  
> file size, rather than "item 2", etc.
>
> However, this doesn't work as it should on Windows.
> The docs say
>
>
>>     * The file's access permissions
>>     * The file's creator and file type (Mac OS and OS X only)
>> Any attribute that is not supported on the current system is  
>> reported as "0" (zero).
>>
>>
> But in fact on Windows, the creator and file type (not supported)  
> are set to empty, not "0".
> This is a real pain, because it means that you always have an empty  
> last item - so the number of items is 10.
> [Does the Mac ever return empty Creator and file type ?]
>
> Therefore you need to add a check for the last character being  
> comma, and if it is append some safe string (e.g. a space), before  
> using the negative index numbers.
>
> The second problem is rather more obscure - but if we want to claim  
> to work in 100% of the cases, not 99.99..% we should cover it.
>
> I believe you cannot use a "filter" to match any arbitrary filename  
> you might be given.
>
> filter ... pFileName & ",*"
>  fails because    "name" and "name,date" both match pFileName = "name"
> You might think you could depend on the fact that the files are  
> alphabetic to always get the one you want first (I certainly did  
> when I started writing this email), but you can't.  Using the  
> filename "a,11" will falsely match the file "a" if it happens to be  
> 11 bytes long (or 110, or 11234, ...). Since "a" comes before "a,
> 11" it will be the first one found.
>
> You could try (I did !!) using the trick I saw from Richard a  
> couple of weeks ago, using a complex filter expression to ensure  
> the right number of items - e.g.
>   filter ... pFileName & ",*,*,*,*,*,*,*,*,*,*"  but that also  
> fails the "a,11" case as above.
>
> So I think you need to loop through them, checking the file name.  
> But you cannot do as Dave suggested, and compare item 1 of each  
> line against the file name, because that would fail to match a  
> filename containing a comma that should match.
> You instead need to compare "item 1 to -11"  (once you've done the  
> above check for empty last item).
>
> So we finish up with what I *think* is a truly reliable version
>
> function CreatorAndType pFilePath
>  local tDefaultFolder,tFile,tCreatorType, theLine, L, tNewFiles, tName
>  -----
>  if the platform <> "MacOs" then return "Error: filetype not  
> supported"
>  put the defaultFolder into tDefaultFolder
>  set the itemdel to slash
>  set the defaultFolder to item 1 to -2 of pFilePath
>  put urlDecode(the detailed files) into tFile
>  put empty into tNewFiles
>  put item -1 of pFilePath into tName
>  set the itemDel to comma
>  repeat for each line L in tFile
>    put L into theLine
>    if the last char of theLine = comma then put space after theLine
>    if item 1 to -11 of theLine = tName then put L & cr after tNewFiles
>  end repeat
>  put tNewFiles into tFile
>  -- put tFile & cr after msg
>  if tFile = empty then return "Error: could not find file"
>  set the defaultFolder to tDefaultFolder
>  return tFile
> end CreatorAndType
>
>
>
>> Le 30 juil. 05 à 13:07, Dave Cragg a écrit :
>>
>>
>>> On 30 Jul 2005, at 10:40, Eric Chatonet wrote:
>>>
>>>
>>>
>>>> Hi Brian,
>>>>
>>>> As the files function returns a list sorted by alphabetical  
>>>> order,  I don't think it's necessary.
>>>>
>>>>
>>>
>>>
>>> But, for example, if you were looking for a file named  
>>> "mend.png"  and there was a file named "amend.png" in the folder,  
>>> you'd find  "amend.png".
>>>
>>> A bit cumbersome, but when I've done this, I've repeated through  
>>> all lines in the detailed files and done a match on the first  
>>> item  in each.
>>>
>>> Cheers
>>> dave
>>>
>>
>>
>>
>> Best Regards from Paris,
>>
>> Eric Chatonet.
>> ----------------------------------------------------------------
>> So Smart Software
>>
>> For institutions, companies and associations
>> Built-to-order applications: management, multimedia, internet, etc.
>> Windows, Mac OS and Linux... With the French touch
>>
>> Free plugins and tutorials on my website
>> ----------------------------------------------------------------
>> Web site        http://www.sosmartsoftware.com/
>> Email        [hidden email]/
>> Phone        33 (0)1 43 31 77 62
>> Mobile        33 (0)6 20 74 50 86
>> ----------------------------------------------------------------
>>
>> _______________________________________________
>> use-revolution mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your  
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>
>>
>>
>
>
> --
> Alex Tweedly       http://www.tweedly.net
>
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.338 / Virus Database: 267.9.6/59 - Release Date:  
> 27/07/2005
>
> _______________________________________________
> use-revolution mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
>

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Getting the type code of a file under OSX

Eric Chatonet
Hi all who follow this thread,

This list is great since it forces us to try to reach excellence :-)
I thought I have posted the last one.
No ;-)
It does work but can be more elegant:

function CreatorAndType pFilePath
   local tDefaultFolder,tFile,tCreatorType
   -----
   if the platform <> "MacOs" then return "Error: filetype not  
supported"
   put the defaultFolder into tDefaultFolder
   set the itemdel to slash
   set the defaultFolder to item 1 to -2 of pFilePath
   put the detailed files into tFile
   filter tFile with urlEncode(item -1 of pFilePath) & ",*"
   set the defaultFolder to tDefaultFolder
   set the itemDel to comma
   put item 11 of tFile into tCreatorType
   if tCreatorType = empty then return "Error: could not determine  
the filetype"
   return char 1 to 4 of tCreatorType,char 5 to 8 of tCreatorType
end CreatorAndType

Have a nice week-end,

Best Regards from Paris,

Eric Chatonet.

Le 30 juil. 05 à 16:24, Eric Chatonet a écrit :

> I should not have thought that such a tiny problem could go so far :-)
> Error management is the key of good software...
> So, I propose another approach:
> As usual, is this one the last one?
> :-)
>
> function CreatorAndType pFilePath
>   local tDefaultFolder,tFile,tCreatorType
>   -----
>   if the platform <> "MacOs" then return "Error: filetype not  
> supported"
>   put the defaultFolder into tDefaultFolder
>   set the itemdel to slash
>   set the defaultFolder to item 1 to -2 of pFilePath
>   put the detailed files into tFile
>   filter tFile with urlEncode(item -1 of pFilePath) & ",*"
>   set the defaultFolder to tDefaultFolder
>   set the itemDel to comma
>   if last char of tFile = comma then return "Error: could not  
> determine the filetype"
>   return char 1 to 4 of item -1 of tFile,char 5 to 8 of item -1 of  
> tFile
> end CreatorAndType


----------------------------------------------------------------
So Smart Software

For institutions, companies and associations
Built-to-order applications: management, multimedia, internet, etc.
Windows, Mac OS and Linux... With the French touch

Free plugins and tutorials on my website
----------------------------------------------------------------
Web site        http://www.sosmartsoftware.com/
Email        [hidden email]/
Phone        33 (0)1 43 31 77 62
Mobile        33 (0)6 20 74 50 86
----------------------------------------------------------------

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

[FR] [EN]Re: Getting the type code of a file under OSX

Dom-2
Eric Chatonet <[hidden email]> wrote:

> function CreatorAndType pFilePath
>    local tDefaultFolder,tFile,tCreatorType

oui c'est pas mal du tout !
very nice, indeed!

a propos de déclaration des "locals" : n'est-il pas préférable de les
déclarer en-tête du script du controle, en dehors des handlers ?
about "locals" statement: is it preferable to place it in the "header"
of the control script, outside of any handler?

--
Revolutionario (not so much, indeed)

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Getting the type code of a file under OSX

Alex Tweedly
In reply to this post by Richard Gaskin
Richard Gaskin wrote:

> Alex Tweedly wrote:
>
>> You could try (I did !!) using the trick I saw from Richard a couple
>> of weeks ago, using a complex filter expression to ensure the right
>> number of items - e.g.
>>   filter ... pFileName & ",*,*,*,*,*,*,*,*,*,*"  but that also fails
>> the "a,11" case as above.
>
>
> For grabbing just one line I often just include boundaries around the
> text with lineOffset:
>
>   put lineoffset(cr& tMyFileame&"," , cr& tFileList)
>
> Because the file names are URL encoded commas become %2C, so I don't
> believe there's a risk of getting commas in the name confused with
> delimiters.

There is a danger if you urlDecode() them first, which the code sample did.
You're quite right - if you urlEncode() the file name passed in, that is
a much safer, and easier,  method.

--
Alex Tweedly       http://www.tweedly.net



--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.338 / Virus Database: 267.9.6/59 - Release Date: 27/07/2005

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: [FR] [EN]Re: Getting the type code of a file under OSX

Eric Chatonet
In reply to this post by Dom-2
Hi Dom,

Tu peux faire les deux mais ce n'est pas la même chose.
You can do both but it's not the same.

Quand les variables sont déclarées en tête du script, leurs valeurs  
sont alors accessibles par toutes les procédures du script.
When variables are declared outside the handlers their values are  
available to all handlers in the script.

Quand elles sont déclarées à l'intérieur d'une procédure, leur valeur  
n'existe que pour la procédure considérée.
When they are declared inside a handler, their values are only  
available for this handler.

Le 30 juil. 05 à 17:24, Dom a écrit :

> Eric Chatonet <[hidden email]> wrote:
>
>
>> function CreatorAndType pFilePath
>>    local tDefaultFolder,tFile,tCreatorType
>>
>
> oui c'est pas mal du tout !
> very nice, indeed!
>
> a propos de déclaration des "locals" : n'est-il pas préférable de les
> déclarer en-tête du script du controle, en dehors des handlers ?
> about "locals" statement: is it preferable to place it in the "header"
> of the control script, outside of any handler?
>
> --
> Revolutionario (not so much, indeed)


Best Regards from Paris,

Eric Chatonet.
----------------------------------------------------------------
So Smart Software

For institutions, companies and associations
Built-to-order applications: management, multimedia, internet, etc.
Windows, Mac OS and Linux... With the French touch

Free plugins and tutorials on my website
----------------------------------------------------------------
Web site        http://www.sosmartsoftware.com/
Email        [hidden email]/
Phone        33 (0)1 43 31 77 62
Mobile        33 (0)6 20 74 50 86
----------------------------------------------------------------

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: [FR] [EN]Re: Getting the type code of a file under OSX

Alex Tweedly
Eric Chatonet wrote:

> Hi Dom,
>
> Tu peux faire les deux mais ce n'est pas la même chose.
> You can do both but it's not the same.
>
> Quand les variables sont déclarées en tête du script, leurs valeurs  
> sont alors accessibles par toutes les procédures du script.
> When variables are declared outside the handlers their values are  
> available to all handlers in the script.
>
> Quand elles sont déclarées à l'intérieur d'une procédure, leur valeur  
> n'existe que pour la procédure considérée.

Quand possible, c'est préférable.

> When they are declared inside a handler, their values are only  
> available for this handler.

And so, IMHO, it is better to declare them inside unless you explicitly
want, and need, to share them - more safety from possible mistakes.

(Sorry about the terse French translation - the fewer words you use, the
fewer chances of mistakes :-)

--
Alex Tweedly       http://www.tweedly.net



--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.338 / Virus Database: 267.9.6/59 - Release Date: 27/07/2005

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: [FR] [EN]Re: Getting the type code of a file under OSX

Eric Chatonet
Right Alex!
Very comprehensive French and Transcript :-)

Le 30 juil. 05 à 17:44, Alex Tweedly a écrit :

> Eric Chatonet wrote:
>
>
>> Hi Dom,
>>
>> Tu peux faire les deux mais ce n'est pas la même chose.
>> You can do both but it's not the same.
>>
>> Quand les variables sont déclarées en tête du script, leurs  
>> valeurs  sont alors accessibles par toutes les procédures du script.
>> When variables are declared outside the handlers their values are  
>> available to all handlers in the script.
>>
>> Quand elles sont déclarées à l'intérieur d'une procédure, leur  
>> valeur  n'existe que pour la procédure considérée.
>>
>
> Quand possible, c'est préférable.
>
>
>> When they are declared inside a handler, their values are only  
>> available for this handler.
>>
>
> And so, IMHO, it is better to declare them inside unless you  
> explicitly want, and need, to share them - more safety from  
> possible mistakes.
>
> (Sorry about the terse French translation - the fewer words you  
> use, the fewer chances of mistakes :-)
>
> --
> Alex Tweedly       http://www.tweedly.net
>
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.338 / Virus Database: 267.9.6/59 - Release Date:  
> 27/07/2005
>
> _______________________________________________
> use-revolution mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
>

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: [FR] [EN]Re: Getting the type code of a file under OSX

Dom-2
In reply to this post by Eric Chatonet
Eric Chatonet <[hidden email]> wrote:

> Quand les variables sont déclarées en tête du script, leurs valeurs  
> sont alors accessibles par toutes les procédures du script.
> When variables are declared outside the handlers their values are  
> available to all handlers in the script.

OK
(it's gone bilingual ;-))
 
> Quand elles sont déclarées à l'intérieur d'une procédure, leur valeur
> n'existe que pour la procédure considérée.
> When they are declared inside a handler, their values are only  
> available for this handler.

OK!

When I have a complex script with calls to another "procédures", it is
therefore better to explicitly declare the variables used by the main
script and its "procédures" (the handlers, commands and fucntions)
called by this main handler (hard to speak of, not confusing between
"script" = all the handlers in a control, and the handlers composing the
script)

By the way, I made the choice of "explicit variables"...
Nonetheless, Rev allows to use implicit variables shared by handlers
among a given script -- but better to declare them as locals?
I remember that in HC you had to resort on globals in this case...
You ended a session with a number of globals you didnt' remember of ;-)

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Getting the type code of a file under OSX

Howard Bornstein
In reply to this post by Howard Bornstein
Thanks for all the nice refinements to the basic algorithm. I
originally used a script like the one Dave Cragg mentioned.

But doesn't it strike everyone that this is cumbersome for such a
simple request.

Perhaps I should enter a BZ enhancement for a function:

getFileAttributes(filepath) that returns one detailed line á la long files.

--
Regards,

Howard Bornstein
-----------------------
www.designeq.com
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: [FR] [EN]Re: Getting the type code of a file under OSX

Dom-2
In reply to this post by Eric Chatonet
To Eric and Alex:

> Tu peux faire les deux mais ce n'est pas la même chose.
> You can do both but it's not the same.

Euh, si c'était possible de ne PAS faire de copie en Mail... Merci ;-)
Eeeer, is it possible NOT to send a copy in Mail... Thanks ;-)

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
12