diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dc05d4e..47eea89 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,20 +16,23 @@ jobs: release: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v2 - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.16 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 - - name: Build - run: mkdir release|| go build -v ./... -o ./release/tidy-files-script-linux-64 + - name: Build-dirRenameCopy + run: mkdir release||cd ./dirRenameCopy || go get || go build -o ../release/dirRenameCopy - - name: Create a Release - if: ${{ github.event.inputs.releaseVersion != '' }} - uses: elgohr/Github-Release-Action@main - env: - GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} - with: - args: "v0.0.1" + - name: Build-tagClassification + run: mkdir release||cd ./tagClassification || go get || go build -o ../release/tagClassification + + - name: Create a Release + if: ${{ github.event.inputs.releaseVersion != '' }} + uses: elgohr/Github-Release-Action@main + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} + with: + args: "v0.0.2" diff --git a/.gitignore b/.gitignore index ba54652..7f21017 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ # golang /pkg http-client.private.env.json +go.sum diff --git a/dirRenameCopy/go.mod b/dirRenameCopy/go.mod index 57115ad..41bfbd9 100644 --- a/dirRenameCopy/go.mod +++ b/dirRenameCopy/go.mod @@ -1,5 +1,10 @@ module github.com/daizc311/TidyFilesScript/dirRenameCopy -require github.com/sirupsen/logrus v1.8.1 +require ( + github.com/daizc311/TidyFilesScript/config v0.0.0 + github.com/sirupsen/logrus v1.8.1 +) + +replace github.com/daizc311/TidyFilesScript/config => ../config go 1.16 diff --git a/dirRenameCopy/main.go b/dirRenameCopy/main.go index 8c82d49..865f8a6 100644 --- a/dirRenameCopy/main.go +++ b/dirRenameCopy/main.go @@ -2,10 +2,11 @@ package main import ( "container/list" + "github.com/daizc311/TidyFilesScript/config" log "github.com/sirupsen/logrus" "os" "strings" - "github.com/daizc311/TidyFilesScript/config" + "syscall" "time" ) @@ -23,15 +24,13 @@ var suffixList = func() *list.List { func main() { config.InitLog() log.SetFormatter(config.JsonLogFormatter()) - currentPath = "F:\\test" scanDirList(currentPath) - } func getSuffix(fileName string) string { for i := suffixList.Front(); i != nil; i = i.Next() { - if strings.HasSuffix(fileName, i.Value.(string)) { + if strings.HasSuffix(strings.ToLower(fileName), i.Value.(string)) { return i.Value.(string) } } @@ -63,12 +62,21 @@ func scanDirList(dirPath string) { continue } moveFile(originalFilePath, targetFilePath) + rmDir(path) } } } } } +func rmDir(path string) { + log.Infof("开始删除目录=>\n目标路径: %s", path) + err := syscall.Rmdir(path) + if err != nil { + log.Errorf("删除目录失败: %s", err.Error()) + } +} + func moveFile(originalFilePath string, targetFilePath string) { log.Infof("开始移动文件=>\n当前文件路径: %s \n目标文件路径: %s", originalFilePath, targetFilePath) err := os.Rename(originalFilePath, targetFilePath) @@ -78,12 +86,14 @@ func moveFile(originalFilePath string, targetFilePath string) { } func getTargetDirByDate(path string, now time.Time) (string, error) { + dateStr := now.Format("20060102") dirPath := path + string(os.PathSeparator) + dateStr var _, err = os.Stat(dirPath) if err != nil { if os.IsNotExist(err) { + log.Infof("目录不存在,创建输出目录=>\n目标路径: %s", dirPath) err := os.Mkdir(dirPath, os.ModePerm) if err != nil { return dirPath, err diff --git a/release/dirRenameCopy.exe b/release/dirRenameCopy.exe new file mode 100644 index 0000000..3b1e2c4 Binary files /dev/null and b/release/dirRenameCopy.exe differ diff --git a/release/tagClassification.exe b/release/tagClassification.exe new file mode 100644 index 0000000..426186d Binary files /dev/null and b/release/tagClassification.exe differ diff --git a/tagClassification/go.mod b/tagClassification/go.mod index 55b29db..6e301bf 100644 --- a/tagClassification/go.mod +++ b/tagClassification/go.mod @@ -1,5 +1,10 @@ module github.com/daizc311/TidyFilesScript/tagClassification -require github.com/sirupsen/logrus v1.8.1 +require ( + github.com/daizc311/TidyFilesScript/config v0.0.0 + github.com/sirupsen/logrus v1.8.1 +) + +replace github.com/daizc311/TidyFilesScript/config => ../config go 1.16 diff --git a/tagClassification/mian.go b/tagClassification/mian.go index ffef6d4..9bb3575 100644 --- a/tagClassification/mian.go +++ b/tagClassification/mian.go @@ -1,12 +1,12 @@ package main import ( + "github.com/daizc311/TidyFilesScript/config" log "github.com/sirupsen/logrus" "os" "path" "regexp" "strings" - "tidy-files-script/config" ) // 获取相对路径