Filtering file name symbols using golang


Filtering file name symbols using golang

Recently, the customer service department has encountered a problem: it’s connected with a third party to mail files. Every time you send a file, you need to upload it. It happens that the name of the uploaded file doesn’t support special symbols such as “% &”. It’s too troublesome to change it manually, so I think of a small tool to use go

package main

import (

func main() {
    var yes int
    fmt.Println (enter 1 to rename the current folder file, otherwise enter 2:)
    if yes != 1 {
    path := "./"
    files, err := ioutil.ReadDir(path)
    if err != nil {

    for _, f := range files {

        if f.IsDir() {

        //To define rules here, I need to filter from (2020) 0854-0036-1355 to 2020085400361355
        str1 := strings.Replace(f.Name(), "-", "", -1)
        str2 := strings.Replace(str1, "(", "", -1)
        str3 := strings.Replace(str2, ")", "", -1)
        //os.Rename(path+"\"+f.Name(), path+"\"+
        //    fmt.Sprintf(str3, index))
        os.Rename(path+"\"+f.Name(), path+"\"+

The advantage of go is cross platform and go build directly xxx.go And then send it to colleagues to run it!