Created
August 30, 2017 06:14
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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