csv - folder and file access in go lang not working when using sub-directory -
I have started using go, actually in the last week I was working on a little import application for CSV files. And now I am struggling with the way to read directories and files.
I want to read a folder, search for CSV files and save the content per CSV file so that I can send per file content through a duplicate request.
This is my code:
func GetFileContent (filename string) ([] [] string, error) {file, err: = os.Open (fileName) if mistake! = Zero {log.Println ("was an error:", mistake) return zero, error} file suspend. Close () Reader: = csv.NewReader (file) Reader. FiltersPRRcord = -1 CSV fileSource, err: = reader.ReadAll () if it's a mistake! = {} String, error) {var result [] string directory [syn: (error), (), error: = os.Open (importPath) error! = Zero {return result, error} Suspend directory. Close () files, err: = directory.Readdir (-1) if err! = Nil {return result, err} _, for file: = class files {if file.Mode (). IsRegular () {if filep Ath.Ext (fileName ()) == "." + FileExtension {log.Println ("import files:", file.Name ()) results = enclosed (result, file.Name ())}}} if LAN (result) == 0 {log.Println ("no import No file type "+ fileExtension +" was found.) Print. ("Import dropped.")} Return result, zero} Any idea why I still do not Error found: Open: When I do not use the root folder / my application's work directory, but any other (original) folder contains such a file Do not have this directory? It works by the time I use it as a /. Source folder.
Can it be solved with just a few small changes or do I have another package And / or function?
Returns the name of the file. You need the directory name with the base name.
Change this line in GetFiles
Parameter In = attachment (results, file.Name ())
Result = Sum (results Failpth Kjoind (Ayatpath file. Name ()))
Comments
Post a Comment