sort by kind

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
yusef88
Posts: 1126
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

sort by kind

Post by yusef88 »

Can XY sort files by kind e.g. group videos, audio, office, text files together?

highend
Posts: 13317
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: sort by kind

Post by highend »

Sure. Write a custom column script...
One of my scripts helped you out? Please donate via Paypal

yusef88
Posts: 1126
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: sort by kind

Post by yusef88 »

may you please explain this?

highend
Posts: 13317
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: sort by kind

Post by highend »

You need a script for a custom column that

- reads in all known generic file types - get("genericfiletype"...
- looks which gft the extension of the current item - <cc_item>
matches and return the gft name so you can sort with this column afterwards

Or you do the get("generic...
creation only one time, save it into a permanent variable and shorten the cc-script
to compare the extension with that list. Faster and more efficient because
the gfts change... very rarely^^
One of my scripts helped you out? Please donate via Paypal

yusef88
Posts: 1126
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: sort by kind

Post by yusef88 »

Thanks for your interaction

this works fine as normal script

Code: Select all

    $Video = "mp4|mkv";
    $Image = "jpg|png";
    $ext = getpathcomponent(<curitem>, "ext"); 
    if ("|$Video|" LikeI "*|$ext|*") {echo "Video"}
but as custom column doesn't work

Code: Select all

    $Video = "mp4,mkv";
    $Image = "jpg,png";
    $ext = getpathcomponent(<cc_name>, "ext");
    if ("|$Video|" LikeI "*|$ext|*") {return video}
    if ("|Image|" LikeI "*|$ext|*") {return Image}
also I do not know how I should use this:

Code: Select all

get("genericfiletype", "{:Video}", "|");
I want custom column look like this
Attachments
2017-04-10_232245.png
2017-04-10_232245.png (1 KiB) Viewed 1629 times

highend
Posts: 13317
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: sort by kind

Post by highend »

Do you actually read your code?

Code: Select all

    $Video = "mp4,mkv";
    $Image = "jpg,png";
    $ext = getpathcomponent(<cc_name>, "ext");
    if ("|$Video|" LikeI "*|$ext|*") {return "Video";}
    if ("|Image|" LikeI "*|$ext|*") {return "Image";}
LikeI checks for | and you use , as a separator
Image is not a variable here
Quote your strings^^
One of my scripts helped you out? Please donate via Paypal

yusef88
Posts: 1126
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: sort by kind

Post by yusef88 »

how to match folders?

highend
Posts: 13317
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: sort by kind

Post by highend »

Code: Select all

exists()
One of my scripts helped you out? Please donate via Paypal

yusef88
Posts: 1126
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: sort by kind

Post by yusef88 »

Final script :D and no need to quote variables.. thanks for your help

Code: Select all

    $ext = "<cc_ext>";

    $Video = get("genericfiletype", "{:Video}", "|");
    $Audio = get("genericfiletype", "{:Audio}", "|");
    $Image = get("genericfiletype", "{:Image}", "|");
    $Subtitle = "srt|ass|ssa|sub|smi|sup|lrc";
    $Text = get("genericfiletype", "{:Text}", "|");
    $Archive = get("genericfiletype", "{:Archive}", "|");
    $Office = get("genericfiletype", "{:Office}", "|");
    $Executable = get("genericfiletype", "{:Executable}", "|");
    $Web = get("genericfiletype", "{:Web}", "|");
    $Font = get("genericfiletype", "{:Font}", "|");

    if (<cc_isfolder> == 1) { return Folder }
    if ("|$Video|" LikeI "*|*.$ext|*") { return video }
    if ("|$Audio|" LikeI "*|*.$ext|*") { return Audio }
    if ("|$Image|" LikeI "*|*.$ext|*") { return Image }
    if ("|$Subtitle|" LikeI "*|$ext|*") { return Subtitle }
    if ("|$Text|" LikeI "*|*.$ext|*") { return Text }
    if ("|$Archive|" LikeI "*|*.$ext|*") { return Archive }
    if ("|$Office|" LikeI "*|*.$ext|*") { return Office }
    if ("|$Executable|" LikeI "*|*.$ext|*") { return Executable }
    if ("|$Web|" LikeI "*|*.$ext|*") { return Web }
    if ("|$Font|" LikeI "*|*.$ext|*") { return Font }
    if ($ext != "") { return Other }
    if ($ext = "*.") { return Unknown }
    

highend
Posts: 13317
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: sort by kind

Post by highend »

and no need to quote variables
I didn't say quote your variables, I said "quote your strings" (which you aren't...)
And btw, why do you quote variables? ;)

Code: Select all

$ext = "<cc_ext>";
<cc_ext> is a variable, no need to quote it in this context

While what you're doing here works, it is very inefficient.

1. Each single item in your list get's all genericfiletypes that you've defined here

Let's say you've generated a list like that (just for demonstration):

Code: Select all

Archive|7z,bz,bz2,cab,gz,Img,iso,lha,lzh,rar,tar,taz,tbz,tbz2,tgz,tz,wmz,wsz,yfs,z,zip,zipx
Audio|wav,mp3,mid,cda,au,ogg,ape,m4a,mpc,mp+,mpp,wma,asf,flac,aif,aiff,aifc,au,wv,wva
Executable|bat,cmd,com,exe,scr
Font|fon,ttf,otf,pfb,pfm
Image|gif,ico,cur,emf,wmf,png,bmp,dib,rle,tga,tpic,dds,hdr,pic,pict,jpg,jpeg,jpe,psb,psd,arw,cpt,cr2,crw,dcr,dng,erf,fff,mrw,mef,nef,nrw,orf,pef,raf,raw,rw2,rwl,sr2,srf,srw,x3f,tif,tiff
Office|cdr,csv,rtf,doc,dot,docm,docx,dotx,xls,xlt,xlsm,xlsx,xltx,ppt,pot,pps,pptx,potx,ppsx,odt,ods,odp,wpd,wpf,one,pdf,eps,jtx,xps,oxps,dwg,dwf,dwfx,dxf,easmx,edrwx,eprtx,sldprt,sldasm,slddrw,eml,msg,nws,zip
Photo|jpg,jpeg,jpe,tif,tiff,arw,cpt,cr2,crw,dcr,dng,erf,fff,mrw,mef,nef,nrw,orf,pef,raf,raw,rw2,rwl,sr2,srf,srw,x3f,tif,tiff,psb,psd
Text|adml,admx,ahk,asc,asp,aspx,au3,b64,bas,bat,c,htaccess,cer,cfg,cmd,cls,conf,config,cnt,ctl,cpp,crt,cs,css,cws,cue,dat,eml,filters,frm,h,hpp,htc,htm,html,ics,idl,inc,inf,ini,java,js,json,less,lng,log,lrc,lst,lua,m3u,m3u8,manifest,man,map,markdown,md,mht,mhtm,mhtml,mim,mk,msg,nfo,nsi,nws,odl,opml,php,pl,prj,py,pyw,rc,rdf,reg,resx,rst,scss,sh,sql,srt,tbl,txt,uue,url,utf8,vb,vbp,vbs,vbw,vcf,website,wpl,ws,xml,xsd,xsl,xslt,xxe,xys
Vector|ai,cdr,cgm,dwg,dwf,dwfx,dxf,emf,eps,epsf,pdf,ps,svf,svg,svgz,wmf,jtx,xps,oxps
Video|3gp,asf,avi,blend,divx,flv,mov,qt,mkv,mpg,mpeg,mpa,mpe,m1v,m2v,mp2,mp4,m4r,m4v,mpv,mpv2,mts,m2ts,ogm,ra,ram,rm,rmvb,vob,ts,webm,wmv
Web|htm,html,shtml,mht,mhtm,mhtml,php,php3,php4,php5,htaccess,cfg,inc,asp,aspx,xml,swf,svg,svgz,url,zip
Assign it as a permanent variable ($genericFileTypes)

And then the code for a cc can be shortened like that (missing your folder, other and unknown checks):

Code: Select all

    perm $genericFileTypes;
    $match = gettoken(regexmatches($genericFileTypes, "(^.*(\||,)<cc_ext>(,|$))", <crlf>), 1, <crlf>);
    return gettoken($match, 1, "|");
One of my scripts helped you out? Please donate via Paypal

yusef88
Posts: 1126
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: sort by kind

Post by yusef88 »

clean and clever :tup: very thanks.

Post Reply