func (fileMover FileMover) MoveFileWithRename(sourcePath string, destPath string) (string, error) {
	if !fileMover.isDryRun {
		destDir := filepath.Dir(destPath)
		if err := fileMover.writeUndoCommandForDirCreate(destDir); err != nil {
			return "", err
		}
		if err := os.MkdirAll(destDir, os.ModePerm); err != nil {
			return "", err
		}
		destPath, err := getNonCollidingPath(destPath)
		if err != nil {
			return "", err
		}
		log.Println("[INFO]", "Moving file", sourcePath, "to", destPath)
		if err := fileMover.writeUndoCommandForFileMove(sourcePath, destPath); err != nil {
			return "", err
		}
		// I frequently get "invalid cross-device link" with os.Rename even on same partition.
		//if err := os.Rename(sourcePath, destPath); err != nil {
		if err := fileMover.moveFile(sourcePath, destPath); err != nil {
			return "", err
		}
	} else {
		log.Println("[INFO]", "Dryrun moving file", sourcePath, "to", destPath)
	}
	return destPath, nil
}
// MoveFileWithRename moves the specified file to the specified path creating the directory if needed, and renaming the file if needed to avoid collission.
MoveFileWithRename moves the specified file to the specified path creating the directory if needed, and renaming the file if needed to avoid collission.
// MoveFileWithRename moves the specified file to the specified path creating the directory if needed and renaming the file if needed to avoid collission .
func (fileMover FileMover) MoveFileWithRename(sourcePath string, destPath string) (string, error) {
	if !fileMover.isDryRun {
		destDir := filepath.Dir(destPath)
		if err := fileMover.writeUndoCommandForDirCreate(destDir); err != nil {
			return "", err
		}
		if err := os.MkdirAll(destDir, os.ModePerm); err != nil {
			return "", err
		}
		destPath, err := getNonCollidingPath(destPath)
		if err != nil {
			return "", err
		}
		log.Println("[INFO]", "Moving file", sourcePath, "to", destPath)
		if err := fileMover.writeUndoCommandForFileMove(sourcePath, destPath); err != nil {
			return "", err
		}
		if err := fileMover.moveFile(sourcePath, destPath); err != nil {
			return "", err
		}
	} else {
		log.Println("[INFO]", "Dryrun moving file", sourcePath, "to", destPath)
	}
	return destPath, nil
}
func ( fileMover FileMover ) MoveFileWithRename ( sourcePath string , destPath string ) ( string , error ) { if ! fileMover . isDryRun { destDir := filepath . Dir ( destPath ) if err := fileMover . writeUndoCommandForDirCreate ( destDir ) ; err != nil { return " " , err } if err := os . MkdirAll ( destDir , os . ModePerm ) ; err != nil { return " " , err } destPath , err := getNonCollidingPath ( destPath ) if err != nil { return " " , err } log . Println ( " " , " " , sourcePath , " " , destPath ) if err := fileMover . writeUndoCommandForFileMove ( sourcePath , destPath ) ; err != nil { return " " , err } if err := fileMover . moveFile ( sourcePath , destPath ) ; err != nil { return " " , err } } else { log . Println ( " " , " " , sourcePath , " " , destPath ) } return destPath , nil }
MoveFileWithRename moves the specified file to the specified path creating the directory if needed, and renaming the file if needed to avoid collission.
MoveFileWithRename moves the specified file to the specified path creating the directory if needed and renaming the file if needed to avoid collission .
// I frequently get "invalid cross-device link" with os.Rename even on same partition. //if err := os.Rename(sourcePath, destPath); err != nil {