mIRC Homepage

filename without extension

Posted By: quartz

filename without extension - 09/10/20 05:45 PM

I don't suppose there's $noext is there? to take the extension off a filename

could use $gettok. $noext might just be tidier
Posted By: Dazuz

Re: filename without extension - 09/10/20 06:25 PM

Code
alias noext return $gettok($1,-2--,46)
Posted By: maroon

Re: filename without extension - 09/10/20 07:16 PM

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.
Posted By: quartz

Re: filename without extension - 09/10/20 09:32 PM

what do the double dashes in gettok do out of interest? the --
Posted By: maroon

Re: filename without extension - 09/10/20 11:17 PM

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"
Posted By: Wims

Re: filename without extension - 11/10/20 09:16 PM

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.


© 2020 mIRC Discussion Forums