I looked up golang.org/pkg/os/#File , but still have no idea. Seems there is no way to get file length, did I miss something?
How to get file length in Go?
Go file size First, we get the FileInfo structure with os. Stat . Then we get the size of the file in bytes from the structure with Size function.
Using File#length() method A simple solution is to call the File#length() method that returns the size of the file in bytes. To get the file size in MB, you can divide the length (in bytes) by 1024 * 1024 .
You can check the length of a string using MyFile. Length , where MyFile is the string whose length you want to check. Create an If activity to check the length, and if the length is greater than 20 characters, use a Move File activity to move the file.
FileInfo has a Length property. It returns the size of a file in bytes. We use FileInfo and the Length property to measure file sizes.
(*os.File).Stat()
returns a os.FileInfo
value, which in turn has a Size()
method. So, given a file f
, the code would be akin to
fi, err := f.Stat() if err != nil { // Could not obtain stat, handle error } fmt.Printf("The file is %d bytes long", fi.Size())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With