How to init Rclone

Hi,

I am trying to invoke RClone commands programmatically by using a pre-defined config file. `
Using below sample function

    func Copy(source string, destination string) (fs.Fs, string) {
    	fsrc, srcFileName, fdst := cmd.NewFsSrcFileDst([]string{source, destination})
    	fmt.Println(fsrc, srcFileName, fdst)
    	if srcFileName == "" {
    		return sync.CopyDir(fdst, fsrc)
    	}
    	return operations.CopyFile(fdst, fsrc, srcFileName, srcFileName)
    }

gives me following error:
didn't find backend called "local"

I couldn’t figure out how RClone initializes all the backends.

You need to import the backends you want to use, or all of them - see the main file.

So for example this little script works…

package main

import (
	"fmt"
	"log"

	_ "github.com/ncw/rclone/backend/drive"
	"github.com/ncw/rclone/fs"
)

func main() {
	f, err := fs.NewFs("drive:")
	if err != nil {
		log.Fatal(err)
	}
	entries, err := f.List("")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(entries)
}
1 Like

Thanks @ncw. This worked.

1 Like