packagemainimport (
"fmt""io/fs""path/filepath""time"
)
/*
Create a hashtable, each key is a full file path of a dir, including subdirectory. But excluding a given list of dir names.
then, test speed by go thru the hashtable, check each key existance
*/varxinputdir = "c:/Users/xah/web/"var dir_names_ignore_list = []string{
".git",
"emacs_manual",
"js_es2011",
"js_es2015",
"node_api",
}
// strInArray return true if x equals any of y
// version 2018-11-12
func strInArray(xstring, y []string) bool {
for _, v := range y {
ifx == v {
returntrue
}
}
returnfalse
}
/*
fbuilt_table build a map of a directory.
return a map.
key is filename full path.
value is 1.
result does not contain dir path.
xinputdir is a dir full path
pignorelist is a array of dir names to ignore. files in these dir are ignored.
*/func fbuilt_table(xinputdirstring, pignorelist []string) map[string]int {
varxtable = make(map[string]int)
var doFile = func(xpathstring, xinfo fs.DirEntry, xerrerror) error {
// first thing to do, check error. and decide what to do about it
ifxerr != nil {
fmt.Printf("error [%v] at a path [%q]\n", xerr, xpath)
returnxerr
}
// find out if it's a dir or file, if file, print info
ifxinfo.IsDir() {
if strInArray(filepath.Base(xpath), pignorelist) {
return filepath.SkipDir
}
} else {
xtable[filepath.ToSlash(filepath.Clean(xpath))] = 1
}
returnnil
}
err := filepath.WalkDir(xinputdir, doFile)
if err != nil {
fmt.Printf("error walking the path %q: %v\n", xinputdir, err)
}
returnxtable
}
funcmain() {
var startime = time.Now()
varxtable = fbuilt_table(filepath.ToSlash(filepath.Clean(xinputdir)), dir_names_ignore_list)
var endtime = time.Now()
varxtimediff = endtime.Sub(startime).Seconds()
fmt.Printf("time spend in seconds: %.1f\n", xtimediff)
fmt.Printf("total items: %v\n", len(xtable))
for kk, _ := rangextable {
ifxtable[kk] == 1 {
fmt.Printf("%v\n", kk)
}
}
}
(*
Create a hashtable, each key is a full file path of a dir, including subdirectory. But excluding a given list of dir names.
then, test speed by go thru the hashtable, check each key existance
*)
inputDir = "c:/Users/xah/web/xahlee_info/talk_show/";
dirsToSkip = {
".git",
"emacs_manual",
"js_es2011",
"js_es2015",
"node_api"
};
(* HHHH------------------------------ *)
xfileList = FileNames[
StringExpression[ (_).., {"advent",} , (_).. ],
inputDir,
Infinity]
(*
failed.
problem is, we are trying to write a StringExpression
that matches file full path, but except a list of them.
we failed in creating a negation, e.g.
a StringExpression pattern that match full file path (not just parts),
but does not contain advent.
todo in future.
*)