Reading file that have random name

How can we read the file that have random name. The below file contains some log and i want to extract only certain parameters from the file.
For ex :- (buffer.b59b721b18b8629039d51942cf37460ed.log)

is it the only file in the folder? is it the only file with log extension? is it the only one that starts with buffer?
and most importantly is this question about reading a file with random name or about extracting only certain “parameters” from the file?

It is second file that starts with buffer
Other file are buffer.b59b721b18b8629039d51942cf37460ed.log.meta and date.log
I want to read only buffer.b59b721b18b8629039d51942cf37460ed.log
And the file that starts with buffer changes its name in every 5 minutes

Yes this is the question about reading a file and storing it in temp file to view the extracted contents only.

Is it always the second file? Lexicographically?

Also based on the files you listed, the one you are looking for is the only that starts with ‘buffer’ and ends with ‘log’. Is that what you are after, can we assume it is always the case?

If it is:

package main

import (




func main() {
    f, err := filepath.Glob("buffer.*log")
    if err != nil {

    if len(f) > 0 {

files in the folder:

 ~/Projects/go/golangbridge $ ls -l | egrep "(log|buffer|date)"
-rw-r--r--   1 jabbson  staff     0  6 Jan 08:50 buffer.b59b721b18b8629039d51942cf37460ed.log
-rw-r--r--   1 jabbson  staff     0  6 Jan 08:49 buffer.b59b721b18b8629039d51942cf37460ed.log.meta
-rw-r--r--   1 jabbson  staff     0  6 Jan 08:50 date.log


 ~/Projects/go/golangbridge $ go run .
1 Like

Thanks Karl
This worked for me to get file name.
Can you explain how can i get the filtered content from the file and view it by running its executable file ?

I am not entirely sure what you mean, what is filtered content? running what? Please explain.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.