Golang os.File.Chdir() function example
package os
Golang os.File.Chdir() function usage example
NOTE : The binary could be executing from somewhere else and changing to the target directory of the file can make life easier for file level operations such as combining different files or splitting files.
file, err := os.Open("/anotherdir/fileinthisdirectory.txt")
if err != nil {
fmt.Println(err)
continue
}
err = file.Chdir() // change current working directory to the file's directory - /anotherdir
file.Close()
See also : https://www.socketloop.com/tutorials/golang-how-to-split-or-chunking-a-file-to-smaller-pieces
References :
Advertisement
Something interesting
Tutorials
+25.7k Golang : missing Mercurial command
+31.5k Golang : bufio.NewReader.ReadLine to read file line by line
+5.6k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+19.4k Golang : How to count the number of repeated characters in a string?
+20.2k Golang : Reset or rewind io.Reader or io.Writer
+14.4k Golang : On enumeration
+12k Golang : Convert a rune to unicode style string \u
+10.4k Golang : Generate random integer or float number
+12.8k Golang : http.Get example
+20.2k Golang : Determine if directory is empty with os.File.Readdir() function
+16.9k Golang : How to generate QR codes?
+6.2k Golang & Javascript : How to save cropped image to file on server