mIRC Home    About    Download    Register    News    Help

Print Thread
File Extension #80272 23/04/04 03:17 AM
Joined: Apr 2004
Posts: 66
C
Cyrex Offline OP
Babel fish
OP Offline
Babel fish
C
Joined: Apr 2004
Posts: 66
How can I find out what file extension a specified file is?

I need to have my script check to see if the file a user selects is certain file type. If the file they select is not a file type my script supports, the script returns an error.

Re: File Extension #80273 23/04/04 04:27 AM
Joined: Oct 2003
Posts: 34
S
spling Offline
Ameglian cow
Offline
Ameglian cow
S
Joined: Oct 2003
Posts: 34
It wold help if you gave more details on the script..

I haven't thoroughly tested this, but let's say your filename was in the %FILENAME variable...
this will put the extension in the %FILE.EXT variable:
Code:
set %FILE.EXT $right(%FILENAME,$calc($len(%FILENAME)-$pos(%FILENAME,.,$count(%FILENAME,.))+1))


It will also work for file extension longer or shorter than 3 characters, and files that are like :"little.bown.happy.dog.gif"

Hope that works for you smile

Last edited by spling; 23/04/04 04:46 AM.
Re: File Extension #80274 23/04/04 07:00 AM
Joined: Aug 2003
Posts: 1,831
I
Iori Offline
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
Shorter version wink
set %FILE.EXT . $+ $gettok(%FILENAME,-1,46)
Same without the .dot
set %FILE.EXT $gettok(%FILENAME,-1,46)

Re: File Extension #80275 24/04/04 09:25 AM
Joined: Oct 2003
Posts: 34
S
spling Offline
Ameglian cow
Offline
Ameglian cow
S
Joined: Oct 2003
Posts: 34
just showing me up all over wink

Re: File Extension #80276 24/04/04 10:46 AM
Joined: Aug 2003
Posts: 1,831
I
Iori Offline
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
Nah don't think of it like that. Offering some constructive critisisms. grin