Beispiel #1
0
func replace() {
	files := mcore.GetSubFiles(rootDir, recursive, exts, skipDirs, skipFiles)
	fmt.Printf("Found %d files.\n", len(files))
	for _, item := range files {
		if verbose {
			show(item)
		}
		fileReplace(item, searchStr, replaceStr)
	}
}
Beispiel #2
0
func Search(path string, exts string, recursive bool, skipDirs, skipFiles, content string) {
	files := mcore.GetSubFiles(path, recursive, exts, skipDirs, skipFiles)
	for _, item := range files {
		text, err := mcore.ReadFileAll(item)
		if nil != err {
			continue
		}

		if !strings.Contains(text, content) {
			if verbose {
				fmt.Printf("File: %s not found matches\n", item)
			}
			continue
		} else {
			nums := strings.Count(text, content)
			fmt.Printf("File: %s found %d matches.\n", item, nums)
		}

		//found
		data, err := mcore.ReadFileLines(item)

		if err != nil {
			fmt.Println(err)
			continue
		}

		for lineNum, line := range data {
			if strings.Contains(line, content) {
				fmt.Printf("%d ", lineNum+1)
				lineA := mcore.String(line).Split(content)
				for i, v := range lineA {
					fmt.Printf(v)
					if i != len(lineA)-1 {
						mcon.PrintGreen(content)
					}
				}
				fmt.Println()
			}
		}
	}
}