简体   繁体   中英

How do I move a file into another folder/path with golang

I know about creating a CSV file or opening a CSV file, but I do not know how to move a CSV file to another path.

To move file \Folder_A\file.txt to \Folder_B\file.txt , you can use os library. Here you have a simple example:

 package main

   import (
       "fmt"
       "os"
   )

   func main() {

       err :=  os.Rename("\Folder_A\file.txt", "\Folder_B\file.txt")

       if err != nil {
           fmt.Println(err)
           return
       }
  }

In your case, instead of file.txt , it will be YOUR_FILE.csv . but the idea is the same.

func moveFile(file1, file2 string) error {
   return os.Rename(file1, file2)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM