func (d *ActionRename) Execute(f *File) error {
	parentDir := path.Dir(f.Path)
	if d.ToDirectory != "" {
		parentDir = d.ToDirectory
		if err := os.MkdirAll(parentDir, 0755); err != nil {
			return err
		}
	}

	newName := filepath.Base(f.Path)
	if d.NameTemplate != "" {
		newName = strings.ReplaceAll(d.NameTemplate, "{name}", f.Name)
		newName = strings.ReplaceAll(newName, "{extension}", f.Extension)
	}

	newPath := path.Join(parentDir, newName)

	if _, err := os.Stat(newPath); os.IsNotExist(err) {
		return os.Rename(f.Path, newPath)
	}
	return fmt.Errorf("file [%s] already exists", newPath)
}
// Execute executes the action.
Execute executes the action.
// Execute executes the action .
func (d *ActionRename) Execute(f *File) error {
	parentDir := path.Dir(f.Path)
	if d.ToDirectory != "" {
		parentDir = d.ToDirectory
		if err := os.MkdirAll(parentDir, 0755); err != nil {
			return err
		}
	}
	newName := filepath.Base(f.Path)
	if d.NameTemplate != "" {
		newName = strings.ReplaceAll(d.NameTemplate, "{name}", f.Name)
		newName = strings.ReplaceAll(newName, "{extension}", f.Extension)
	}
	newPath := path.Join(parentDir, newName)
	if _, err := os.Stat(newPath); os.IsNotExist(err) {
		return os.Rename(f.Path, newPath)
	}
	return fmt.Errorf("file [%s] already exists", newPath)
}
func ( d * ActionRename ) Execute ( f * File ) error { parentDir := path . Dir ( f . Path ) if d . ToDirectory != " " { parentDir = d . ToDirectory if err := os . MkdirAll ( parentDir , 0755 ) ; err != nil { return err } } newName := filepath . Base ( f . Path ) if d . NameTemplate != " " { newName = strings . ReplaceAll ( d . NameTemplate , " " , f . Name ) newName = strings . ReplaceAll ( newName , " " , f . Extension ) } newPath := path . Join ( parentDir , newName ) if _ , err := os . Stat ( newPath ) ; os . IsNotExist ( err ) { return os . Rename ( f . Path , newPath ) } return fmt . Errorf ( " " , newPath ) }
Execute executes the action.
Execute executes the action .