This is a creation in Article, where the information may have evolved or changed.
Recently because of learning the go language, so a Python implementation of a script, with the Go language implementation, to practice file operations, regular expressions, and familiar with the go language of many libraries, and read the library of the Go Language source code.
The following is a statistical script that implements the following functions:
1. Open a file in the current directory, loop through a row, and use the strings library, split the string of this line, form a list, and analyze the data in the list;
2. Read all current files, loop processing;
Package Main
Import (
"Bufio"
"FMT"
"IO"
"Log"
"OS"
"RegExp"
"Strings"
"Time"
)
Func Main () {
Defines the variable old for floating-point type, and initializes it to 0.0
Old: = 0.0
for {
Total: = 0.0
Fail: = 0.0
Get the current directory name
DirName, _: = OS. GETWD ()
Dir, _: = OS. OpenFile (dirname, OS. O_rdonly, OS. Modedir)
Read all file names and directory names in the current directory
Names, _: = Dir. Readdir (-1)
Iterate through the current file name
For _, Name: = range Names {
Not a directory, deal with it.
If!name. Isdir () {
S: = name. Name ()
Files matching the name of the AA file
FN, _: = RegExp. Matchstring ("AA", s)
IF FN {
File, err: = OS. Open (s)
If err! = Nil {
Log. Fatal (ERR)
}
Buffer for loading files
r: = Bufio. Newreader (file)
for {
Read a line of files
Line, Err: = r.readstring (' \ n ')
If Io. EOF = = Err | | Nil! = Err {
Break
}
List: = Strings. Split (line, "|")
If LIST[14]! = "0" {
Fail + = 1.0
}
Total + = 1.0
}
File. Close ()
}
}
}
NEW: = Total-old
Old = Total
Success: = Total-fail
Percent: = Int (success/total * 100)
Fmt. Println ("percent=", percent, "total=", Total, "fail=", Fail, "success=", Success, "new=", new)
1 seconds delay
Time. Sleep (1E9)
}
}