ret*_*oot 2 path go

我正在尝试将文件保存到我的桌面,但每当我运行我的脚本时,它会将文件保存在go脚本所在的任何目录中.

这是我正在使用的代码块

func (d *downloader) downloadToFile(key string) {
    // Create the directories in the path
    // desktop path
    desktop := "Desktop/" + d.dir
    file := filepath.Join(desktop, key)
    if err := os.MkdirAll(filepath.Dir(file), 0775); err != nil {
        panic(err)
    }

    // Setup the local file
    fd, err := os.Create(file)
    if err != nil {
        panic(err)
    }
    defer fd.Close()

    // Download the file using the AWS SDK
    fmt.Printf("Downloading s3://%s/%s to %s...\n", d.bucket, key, file)
    params := &s3.GetObjectInput{Bucket: &d.bucket, Key: &key}
    d.Download(fd, params)
    _, e := d.Download(fd, params)
    if e != nil {
        panic(e)
    }
}

我试过这条路

desktop := "Desktop/" + d.dir
desktop := "/Desktop/" + d.dir
desktop := "Desktop/" + d.dir
desktop := "~/Desktop/ + d.dir

我似乎无法将文件保存到桌面,例如当我尝试时

desktop := "~/Desktop/ + d.dir
~~