Ejemplo n.º 1
0
func classify(file, target string, copyMode, fullHashMode bool, classifyMode typeClassifyMode) error {
	err, date := getDateFromExif(file)
	if err != nil {
		err, date = getDateFromModifyTime(file)
	}

	if err != nil {
		return err
	}

	folderPath := ""
	switch classifyMode {
	case monthMode:
		folderPath, err = makeFolderByMonth(target, date)
	case yearMode:
		folderPath, err = makeFolderByYear(target, date)
	case birthdayMode:
		folderPath, err = makeFolderByBirthday(target, date, file)
	case dateMode:
		folderPath, err = makeFolderByDate(target, date)
	}

	if err != nil {
		return err
	}

	targetFile := filepath.Join(folderPath, filepath.Base(file))
	err = pcopylib.CopyFile(file, targetFile, !copyMode, fullHashMode)
	if err != nil {
		return err
	}

	return nil
}
Ejemplo n.º 2
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	if err := parseArgs(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	sourceStatus := pcopylib.IsFileExist(source)
	if sourceStatus == pcopylib.FileExistStatus_NotExist {
		fmt.Println(shortUsage(fmt.Sprintf("pcopy: error: %s: No such file or directory", source)))
		os.Exit(1)
	}

	if sourceStatus == pcopylib.FileExistStatus_File {
		if err := pcopylib.CopyFile(source, target, moveMode, fullHashMode); err != nil {
			fmt.Println(shortUsage(fmt.Sprint(err)))
			os.Exit(1)
		}
	} else {
		if err := pcopylib.CopyDirectory(source, target, moveMode, fullHashMode, recursiveMode); err != nil {
			fmt.Println(shortUsage(fmt.Sprint(err)))
			os.Exit(1)
		}
	}
}