//////////////////////////////////////////////////////////////// // // UCE GETPATHS LIBRARY : // // This file declares all functions based on paths. // // //////////////////////////////////////////////////////////////// // // Made by [Fr]enchBadPunk - 2011 - Public Domain // //////////////////////////////////////////////////////////////// _uninstall_add "getpaths" "_uninstall_getpaths_lib" _uninstall_getpaths_lib = "isfile isfolder ..." //////////////////////////////////////////////////////////////// isfile = [ // $arg1 : "a_path" - Facultative (to get the drive root folder) // Return 1 if it's a file, 0 else. ? (=s (getpathcontents $arg1) "") 1 0 ] isfolder = [ // $arg1 : "a_path" - Facultative (to get the drive root folder) // Return 1 if it's a folder, 0 else. ? (!=s (getpathcontents $arg1) "") 1 0 ] //////////////////////////////////////////////////////////////// isfolderexist = [ // $arg1 : a path to a folder result (isfolder $arg1) ] isfileexist = [ // $arg1 : a path to a file if (= (isfile $arg1) 1) [ ? (= (indexof (getpathcontents (getpathparent $arg1)) (getpathfullname $arg1)) -1) 0 1 ] ] //////////////////////////////////////////////////////////////// getpathcontents = [ // $arg1 : "a_path" (Facultative to get the drive root folder) // $arg2 : 0 for all, "1" for files, "-1" for folders only. // $arg3 : 1 to add the path before each item, 0 else by default. // Returns the choosen list of items that the path contains // formated like that : ("xxx" "yyy") // Correct the path _getpathcontents_path = $arg1 if (|| (=s (substr $arg1 0 1) "/") (=s (substr $arg1 0 1) "\")) [ _getpathcontents_path = (concatword "." $_getpathcontents_path) ] if (&& (!=s (substr $arg1 (- (strlen $arg1) 1) 1) "\") (!=s (substr $arg1 (- (strlen $arg1) 1) 1) "/")) [ _getpathcontents_path = (concatword $_getpathcontents_path "/") ] // Get all contents _getpathcontents_list = "" loopfiles i (concatword $_getpathcontents_path ".") "" [ _getpathcontents_list = (format [%1 "%2"] $_getpathcontents_list $i) ] // Return all if arg2 is "0", only files if arg2 is "1", or only folders if arg2 is "-1" _getpathcontents_result = "" looplist i $_getpathcontents_list [ // Test if it's a file or a folder _getpathcontents_tmp = "" loopfiles t (concatword $_getpathcontents_path $i) "" [ _getpathcontents_tmp = (format [%1 "%2"] $_getpathcontents_tmp $t) ] // Add goods items if (|| ( || ( && (=s $_getpathcontents_tmp "") (= $arg2 1) ) ( && (!=s $_getpathcontents_tmp "") (= $arg2 -1) ) ) ( && (!= $arg2 1) (!= $arg2 -1) ) ) [ _getpathcontents_result = (format [%1 "%3%2"] $_getpathcontents_result $i ( ? (= $arg3 1) $_getpathcontents_path ) ) ] ] result $_getpathcontents_result ( _getpathcontents_result = ; _getpathcontents_path = ; _getpathcontents_tmp = ) ] //////////////////////////////////////////////////////////////// getpathparent = [ result (concatword (substr (substr $arg1 0 (strstrrev (strreplace $arg1 "\" "/") "/")) 0 (strstrrev (strreplace (substr $arg1 0 (strstrrev (strreplace $arg1 "\" "/") "/")) "\" "/") "/")) "/.") ] getpathfullname = [ if (|| (!= (strstr $arg1 "/") -1) (!= (strstr $arg1 "\") -1)) [ if (> (strstrrev $arg1 "/") (strstrrev $arg1 "\")) [ result (substr $arg1 (+ (strstrrev $arg1 "/") 1)) ] [ result (substr $arg1 (+ (strstrrev $arg1 "\") 1)) ] ] ] getpathfilename = [ result (strreplace (getpathfullname $arg1) (concatword "." (getpathextension $arg1)) "") ] getpathextension = [ if (!= (strstr $arg1 ".") -1) [ result (substr $arg1 (+ (strstrrev $arg1 ".") 1)) ] ] getpathextensionslist = [ // $arg1 : a path list _getpathextensionslist_list = $arg1 _getpathextensionslist_tmp = "" _getpathextensionslist_result = "" looplist i $_getpathextensionslist_list [ _getpathextensionslist_tmp = (getpathextension $i) if (= (indexof $_getpathextensionslist_result $_getpathextensionslist_tmp) -1) [ _getpathextensionslist_result = (format [%1 "%2"] $_getpathextensionslist_result $_getpathextensionslist_tmp) ] ] result $_getpathextensionslist_result ( _getpathextensionslist_list = ; _getpathextensionslist_tmp = ; _getpathextensionslist_result = ) ] //////////////////////////////////////////////////////////////// getpathorderlist = [ // $arg1 : the list // $arg2 : 0 to sort in alphabetical order // 1 to sort in alphabetical inverted order (0 & -1) // -1 for reverse the order // 2 for randomize the order _getpathorderlist_list = $arg1 _getpathorderlist_item = "" if (< (listlen $_getpathorderlist_list) 2) [ _getpathorderlist_result = $_getpathorderlist_list ] [ if (= $arg2 2) [ // Randomize _getpathorderlist_tmp = "" while [ (> (listlen $_getpathorderlist_list) 0) ] [ //loop i (listlen $_getpathorderlist_list) [ _getpathorderlist_item = (at $_getpathorderlist_list (rnd (+ (listlen $_getpathorderlist_list) 1))) _getpathorderlist_list = (listdel $_getpathorderlist_list $_getpathorderlist_item) _getpathorderlist_tmp = (concat $_getpathorderlist_tmp $_getpathorderlist_item) ] _getpathorderlist_list = $_getpathorderlist_tmp ( _getpathorderlist_tmp = ) ] [ if (!= $arg2 -1) [ // Sort in alphabetical (a-z) loop i (listlen $_getpathorderlist_list) [ // Take one by one _getpathorderlist_item = (at $_getpathorderlist_list $i) // Replace item if the next is superior loop t (- (listlen $_getpathorderlist_list) (- (+ 1 $i))) [ if (>s (struppercase (at $_getpathorderlist_list (+ (+ $i $t) 1))) (struppercase $_getpathorderlist_item)) [ _getpathorderlist_item = (at $_getpathorderlist_list (+ (+ $i $t) 1)) ] ] // Place item at the begining of the list ( del intem ; (item + list) ) _getpathorderlist_list = (listdel $_getpathorderlist_list $_getpathorderlist_item) _getpathorderlist_list = (concat $_getpathorderlist_item $_getpathorderlist_list) ] ] if (|| (= $arg2 -1) (= $arg2 1)) [ // Reverse _getpathorderlist_item = "" looplist i $_getpathorderlist_list [ _getpathorderlist_item = (concat $i $_getpathorderlist_item) ] _getpathorderlist_list = $_getpathorderlist_item ] ] // Add the "" : _getpathorderlist_item = "" looplist i $_getpathorderlist_list [ _getpathorderlist_item = (format [%1 "%2"] $_getpathorderlist_item $i) ] _getpathorderlist_list = $_getpathorderlist_item ] result $_getpathorderlist_list ( _getpathorderlist_item = ; _getpathorderlist_list = ) ] //////////////////////////////////////////////////////////////// getpathsortedfiles = [ // $arg1 : "a_path" (Facultative to get the drive root folder) // $arg2 : Groupe : 0 by names ; 1 by extensions // $arg3 : Order : 0 none ; -2 Za.Az ; -1 Za.Za ; 1 Az.Az ; 2 Az.Za // $arg4 : 1 to add the path before each item, 0 else by default. // Get lists : _getpathsortedfiles_fileslist = (getpathcontents $arg1 1 $arg4) _getpathsortedfiles_extensionslist = (getpathextensionslist (getpathcontents $arg1 1 0)) // Order lists : if (!= $arg3 0) [ _getpathsortedfiles_fileslist = (getpathorderlist $_getpathsortedfiles_fileslist (? (> $arg3 0) 0 1)) _getpathsortedfiles_extensionslist = ( getpathorderlist $_getpathsortedfiles_extensionslist (? (|| (= $arg3 -2) (= $arg3 1)) 0 1) ) ] // Groupe files extensions : if (!= $arg2 0) [ _getpathsortedfiles_list = "" looplist i $_getpathsortedfiles_extensionslist [ _getpathsortedfiles_tmp = "" looplist t $_getpathsortedfiles_fileslist [ if (=s (getpathextension $t) $i) [ _getpathsortedfiles_tmp = (format [%1 "%2"] $_getpathsortedfiles_tmp $t) ] ] _getpathsortedfiles_tmp = (getpathorderlist $_getpathsortedfiles_tmp (? (> $arg3 0) 0 1)) _getpathsortedfiles_list = (concat $_getpathsortedfiles_list $_getpathsortedfiles_tmp) ] ] [ _getpathsortedfiles_list = $_getpathsortedfiles_fileslist ] result $_getpathsortedfiles_list ( _getpathsortedfiles_fileslist = _getpathsortedfiles_extensionslist = _getpathsortedfiles_tmp = _getpathsortedfiles_list = ) ] // * chars ; ? = 1 char ; ! = 1 letter ; # = 1 number getpathfilter = [ // $arg1 : a filter (like that "ab*e?!!?h##.*") // $arg2 : a list to filter // Returns the filtered list if (&& (> $numargs 1) (&& (!=s $arg1 "") (!=s $arg2 ""))) [ // Corrects the filter _getpathfilter_tmp = $arg2 // ?* => * ; *? => * ; ** => * while [ (!= (strstr $_getpathfilter_tmp "?*") -1) ] [ _getpathfilter_tmp = (strreplace $_getpathfilter_tmp "?*" "*") ] while [ (!= (strstr $_getpathfilter_tmp "*?") -1) ] [ _getpathfilter_tmp = (strreplace $_getpathfilter_tmp "*?" "*") ] while [ (!= (strstr $_getpathfilter_tmp "**") -1) ] [ _getpathfilter_tmp = (strreplace $_getpathfilter_tmp "**" "*") ] // Parse the list _getpathfilter_tmp2 = "" looplist i $arg1 [ _getpathfilter_tmp2 = (getpathfullname $i) loopstr i (getpathfullname $i) [ ] ] // charisletter ; charisnumber ; charisother result $_getpathfilter_tmp ] [ result $arg1 ] ( _getpathfilter_tmp = ) ] // Filter // ** => * // * . ? x // *??*?*.* // *??? => * // SearchFile // ExecAllUnder // Existing internal commands : // listlen $list => number of element (starting at 1 !) // listdel $list $str => newlist // indexof $list $str => index_num // looplist var $list [ body ($var is the index) ] // listfind var $list [ body ($var is the index) ] // instances // counts how many times an element given as the second argument is repeated in a given list. // execdir // executes all the files at the given location. //execdir = [ loopfiles f $arg1 cfg [ exec (format "%1/%2.cfg" $arg1 $f) ] ] //se_filelist = [ // cfglist = ""; // loopfiles f $se_dir "cfg" [ cfglist = (concatword $cfglist $f ".cfg ") ] // result $cfglist //] //se_pathtolist = [ result (strreplace $arg1 "/" " ") ] //se_extractfile = [ result (at (se_pathtolist $arg1) (- (listlen (se_pathtolist $arg1)) 1)) ] //se_extractdir = [ result (strreplace $arg1 (se_extractfile $arg1) "") ] //editcfg = [ se_dir = (se_extractdir $arg1); se_curfile = (se_extractfile $arg1); showgui cfgeditor ]