【发布时间】:2019-12-11 01:17:03
【问题描述】:
我正在尝试将文件保存到我的桌面,但是每当我运行我的脚本时,它都会将文件保存在 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
创建了一个目录~,在~ 内部创建了桌面,在桌面内部创建了 d.dir,所有文件都在其中。同样,我想运行脚本,无论我在哪里运行它,我都想将其内容放在 d.dir 文件夹中,以便在桌面上创建。
【问题讨论】: