Renamed.go

Home   »   Renamed.go

package main

import (
    "fmt"
    "os"
	"io/ioutil"
	"path/filepath"
	"crypto/rand"
	"bufio"

)

func main() {
	reader := bufio.NewReader(os.Stdin)
	actualDir, _ := os.Getwd()
    fmt.Println("Se van a renombrar todos los ficheros de este directorio: "+actualDir)

	fmt.Print("Pulsa una tecla para continuar...")
    reader.ReadString('\n')

	files, _ := ioutil.ReadDir(actualDir)
 
    for _, f := range files {
			if(!f.IsDir()){
				exts := filepath.Ext(f.Name())
				p, _ := rand.Prime(rand.Reader, 50)
				actual := actualDir +"\\" + f.Name()
				new := actualDir +"\\" + p.String() + exts
				os.Rename(actual, new)
				fmt.Println("Renamed - "+f.Name())
			}
    }
    
}

Leave a Reply

Your email address will not be published. Required fields are marked *