You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.4 KiB
64 lines
1.4 KiB
package main
|
|
|
|
import (
|
|
// 导入包,导入前缀为下划线,则init函数被执行,然后注册驱动。
|
|
"fmt"
|
|
"fstool/db"
|
|
"fstool/util"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func main() {
|
|
// 获取信息
|
|
args := os.Args
|
|
// no input
|
|
if args == nil || len(args) < 2 {
|
|
fmt.Printf("input your real path, like /home etc.\n")
|
|
os.Exit(1)
|
|
}
|
|
|
|
// 第一个是输入的参数
|
|
// 路径
|
|
path := args[1]
|
|
//fmt.Printf("your path is :%s\n", path)
|
|
|
|
// open datebase
|
|
db.Init()
|
|
// 创建数据表
|
|
db.CreateTable()
|
|
//遍历
|
|
ftree, err := util.GetDirFilePaths(path, false)
|
|
if err != nil {
|
|
fmt.Printf("scan error is :%v", err)
|
|
}
|
|
//计算hash,然后存放到数据库
|
|
for _, v := range ftree {
|
|
//fmt.Printf("%v\n", v)
|
|
// 计算结果
|
|
//fmt.Printf("%v,%s\n", filepath.Dir(v), filepath.Base(v))
|
|
relpath, err := filepath.Rel(path, v)
|
|
if err != nil {
|
|
fmt.Printf("relpath error :%v", err)
|
|
}
|
|
//fmt.Printf("relpath:%s\n", filepath.Dir(relpath))
|
|
// 拼装文件信息插入数据库
|
|
var stf db.StFileInfo
|
|
stf.Fhash = util.CalacHash(v)
|
|
stf.Fname = filepath.Base(v)
|
|
|
|
// path
|
|
rlpath := filepath.ToSlash(relpath)
|
|
fmt.Printf("relpath:%s\n", filepath.Dir(rlpath))
|
|
rlpath = filepath.Join(rlpath, "/")
|
|
stf.Fpath = filepath.Dir(rlpath)
|
|
|
|
// fmt.Printf("relpath:%s\n", filepath.Dir(rlpath))
|
|
// insert into db
|
|
// fmt.Printf("stf :%v\n", stf)
|
|
db.InsertStf(stf)
|
|
}
|
|
// fmt.Printf("scan is :%v", ftree)
|
|
// connectDB()
|
|
// insert(1, 0.81192)
|
|
}
|
|
|