Skip to content

Instantly share code, notes, and snippets.

@jpastoor
Created August 30, 2017 06:14
Show Gist options
  • Save jpastoor/e2ab14e9126a74d4fa540c2f3cd66abd to your computer and use it in GitHub Desktop.
Save jpastoor/e2ab14e9126a74d4fa540c2f3cd66abd to your computer and use it in GitHub Desktop.
Shortening go filenames in directory to prevent filename too long errors on Windows
package main
import (
"path/filepath"
"os"
"fmt"
"strings"
"strconv"
)
var (
i = 0
)
func main() {
filepath.Walk("C:\\workspace\\go\\src\\github.com\\antihax\\goesi\\esi", visit)
}
// Find .go files and change their varnames to an incrementing integer
func visit(path string, f os.FileInfo, err error) error {
if filepath.Ext(path) == ".go" {
fmt.Println(path)
i++
_, file := filepath.Split(path)
newname := strings.Replace(path, file, strconv.Itoa(i)+".go", 1)
os.Rename(path, newname)
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment