mIRC Home    About    Download    Register    News    Help

Print Thread
filename without extension #267849 09/10/20 05:45 PM
Joined: Dec 2019
Posts: 32
Q
quartz Offline OP
Ameglian cow
OP Offline
Ameglian cow
Q
Joined: Dec 2019
Posts: 32
I don't suppose there's $noext is there? to take the extension off a filename

could use $gettok. $noext might just be tidier

Re: filename without extension [Re: quartz] #267850 09/10/20 06:25 PM
Joined: Dec 2015
Posts: 146
Dazuz Offline
Vogon poet
Offline
Vogon poet
Joined: Dec 2015
Posts: 146
Code
alias noext return $gettok($1,-2--,46)

Re: filename without extension [Re: Dazuz] #267851 09/10/20 07:16 PM
Joined: Jan 2004
Posts: 1,437
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,437
That returns $null if the filename already has no extension. $gettok(string,1--2,46) would do it, but then it gets messy if you have a longfilename where the folder contains a period but the filename doesn't, so you'd need to use $nofile and $nopath, strip the extension, then join them back together.

Re: filename without extension [Re: maroon] #267855 09/10/20 09:32 PM
Joined: Dec 2019
Posts: 32
Q
quartz Offline OP
Ameglian cow
OP Offline
Ameglian cow
Q
Joined: Dec 2019
Posts: 32
what do the double dashes in gettok do out of interest? the --

Re: filename without extension [Re: quartz] #267858 09/10/20 11:17 PM
Joined: Jan 2004
Posts: 1,437
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,437
1. the 1st is a hyphen, the 2nd is a negative https://en.wikichip.org/wiki/mirc/identifiers/$gettok

2. The $gettok also would not properly handle filename like: "Up Up and Away....jpg"

Re: filename without extension [Re: quartz] #267878 11/10/20 09:16 PM
Joined: Jul 2006
Posts: 3,729
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,729
Hello, there is $file() which has various property, including .name, which will give you the name of the file without its extention, but that only works for existing filename.

$nopath works with string though, and can be used on non existing filename, get the position of the last dot in the filename string and get only the portion before that:

Originally Posted by Using maroon's example
//var %n $nopath(Up Up and Away....jpg),%p $pos(%n,.,$calc($pos(%n,.,0) - 1)) | echo -ag > $left(%n,%p)


A handy regex can also do the job: $regsubex($nopath(Up Up and Away....jpg),\.[^.]+$,)


Edit: the $nopath/$pos code only works when there is an extention but can be fixed with some if on %p or something, wheareas I did make the regex works even if there's no extention.



Last edited by Wims; 12/10/20 12:06 AM. Reason: details

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net