In a large Go applcation, I have this code snippet:
fName = filepath.Join(DestPath, fName)
log.Println(fName)
f, err := os.Create(fName)
defer f.Close()
if err != nil {
log.Println(err.Error())
}
This code logs an error : “The filename, directory name, or volume label syntax is incorrect”
This code is invoked from a separate function in the same Go application, while the destination directory is read in a ticker loop like this:
func LoopPendingProcessing(){
interval := 30 * time.Second
tk = time.NewTicker(interval)
for range tk.C {
time.Sleep(100 * time.Millisecond)
PrepPendingFiles()
}
}
This function is called in the ticker loop, and the directory being read is the destination directory of that above mentioned call to os.Create(fName)
.
func PrepPendingFiles() {
t := time.Duration(50 * time.Millisecond)
time.Sleep(t)
fileName, err := os.ReadDir(C:\Master\IncomingData)
if err != nil {
log.Println(err.Error())
}
go xmtToServer(fileName)
}
If I invoke the identical code, file name and target directory from a separate Go application on the same machine, although the same ticker loop is running, the requested file is written to the target directory, with no errors. My hunch is that within the same application, the target directory is blocked by something in the timer loop.
I realize that “The filename, directory name, or volume label syntax is incorrect” can occur in many different scenarios, and many questions have been asked about this Go error. I have not found a question that seems to address my problem.
How can this problem be solved?