-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os: Lstat failed on C:\$Recycle.Bin #13763
Comments
@chai2010 because you don't append last backslash for Join(). package main
import (
"fmt"
"log"
"os"
"path/filepath"
)
func main() {
f, err := os.Open(`C:\`)
if err != nil {
log.Fatal("os.Open:", err)
}
defer f.Close()
names, err := f.Readdirnames(-1)
if err != nil {
log.Fatal("f.Readdirnames:", err)
}
for i, s := range names {
fmt.Println(i, s)
filename := filepath.Join(`C:\`, s)
fileInfo, err := os.Lstat(filename)
if err != nil {
log.Fatal("os.Lstat:", err)
}
fmt.Println("\t", fileInfo.IsDir())
}
} But it will be fail with some system-file on C:\
|
@mattn thanks. |
On my windows10, my modified code above display like below.
So |
@chai2010, what do you think the problem is? I think the problem is that os.Open("C:") currently opens root directory of C: ( I suspect if you run your example program from root directory on C:, it will run just fine. Alex |
@mattn I has the same error as you: @alexbrainman I donot know the reason. I think there are three problems:
The func main() {
const root = `C:\`
err := filepath.Walk(root, func(path string, fi os.FileInfo, err error) error {
if err != nil {
return err
}
fmt.Printf("filepath.Walk: path = %s; isdir = %v\n", path, fi.IsDir())
return nil
})
if err != nil {
log.Fatal("filepath.Walk:", err)
}
fmt.Println("Done")
} |
CL https://golang.org/cl/18184 mentions this issue. |
go version devel +c7c7c70 Mon Dec 28 01:12:24 2015 +0000 windows/amd64
error:
os.Lstat:GetFileAttributesEx C:$Recycle.Bin: The system cannot find the file specified.
The text was updated successfully, but these errors were encountered: