本文整理汇总了Golang中os.FileInfo.IsDirectory方法的典型用法代码示例。如果您正苦于以下问题:Golang FileInfo.IsDirectory方法的具体用法?Golang FileInfo.IsDirectory怎么用?Golang FileInfo.IsDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os.FileInfo
的用法示例。
在下文中一共展示了FileInfo.IsDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: walk
// walk recursively descends path, calling w.
func walk(path string, info *os.FileInfo, walkFn WalkFunc) os.Error {
err := walkFn(path, info, nil)
if err != nil {
if info.IsDirectory() && err == SkipDir {
return nil
}
return err
}
if !info.IsDirectory() {
return nil
}
list, err := readDir(path)
if err != nil {
return walkFn(path, info, err)
}
for _, fileInfo := range list {
if err = walk(Join(path, fileInfo.Name), fileInfo, walkFn); err != nil {
return err
}
}
return nil
}
示例2: visit
func (me *AutoUnionFs) visit(path string, fi *os.FileInfo, err error) error {
if fi.IsDirectory() {
roots := me.getRoots(path)
if roots != nil {
me.addAutomaticFs(roots)
}
}
return nil
}
示例3: directoryExists
func directoryExists(path string) bool {
var f *os.FileInfo
var err os.Error
if f, err = os.Stat(path); err != nil {
return false
}
return f.IsDirectory()
}
示例4: fileInfoToEntry
func (me *fileSystemMount) fileInfoToEntry(fi *os.FileInfo) (out *EntryOut) {
out = &EntryOut{}
splitNs(me.options.EntryTimeout, &out.EntryValid, &out.EntryValidNsec)
splitNs(me.options.AttrTimeout, &out.AttrValid, &out.AttrValidNsec)
CopyFileInfo(fi, &out.Attr)
me.setOwner(&out.Attr)
if !fi.IsDirectory() && fi.Nlink == 0 {
out.Nlink = 1
}
return out
}
示例5: Walk
func (sc *SpecCollector) Walk(path string, f *os.FileInfo, err error) error {
if err != nil {
return err
}
if f.IsDirectory() {
return nil
}
if strings.HasSuffix(f.Name, SpecSuffix) {
*sc = append(*sc, path)
}
return nil
}
示例6: SetRequestMetaData
func (p *Propolis) SetRequestMetaData(req *http.Request, info *os.FileInfo) {
// file permissions: grant "public-read" if the file grants world read permission
if info.Permission()&s_iroth != 0 {
req.Header.Set("X-Amz-Acl", acl_public)
} else {
req.Header.Set("X-Amz-Acl", acl_private)
}
// user id: store the numeric and symbolic names
user, err := user.LookupId(info.Uid)
if err != nil {
req.Header.Set("X-Amz-Meta-Uid", fmt.Sprintf("%d", info.Uid))
} else {
req.Header.Set("X-Amz-Meta-Uid", fmt.Sprintf("%d (%s)", info.Uid, user.Username))
}
// group id: just store the numeric id for now until Go supports looking up group names
req.Header.Set("X-Amz-Meta-Gid", fmt.Sprintf("%d", info.Gid))
// store the permissions as an octal number
req.Header.Set("X-Amz-Meta-Mode", fmt.Sprintf("0%o", info.Mode))
// store the modified date in a nice format
sec := info.Mtime_ns / 1e9
ns := info.Mtime_ns % 1e9
date := time.SecondsToLocalTime(sec).String()
if ns == 0 {
req.Header.Set("X-Amz-Meta-Mtime", fmt.Sprintf("%d (%s)", sec, date))
} else {
req.Header.Set("X-Amz-Meta-Mtime", fmt.Sprintf("%d.%09d (%s)", sec, ns, date))
}
// set the content-type by looking up the MIME type
mimetype := default_mime_type
switch {
case info.IsDirectory():
mimetype = directory_mime_type
case info.IsSymlink():
mimetype = symlink_mime_type
default:
if dot := strings.LastIndex(info.Name, "."); dot >= 0 && dot+1 < len(info.Name) {
extension := strings.ToLower(info.Name[dot:])
if kind := mime.TypeByExtension(extension); kind != "" {
mimetype = kind
}
}
}
req.Header.Set("Content-Type", mimetype)
}
示例7: symbol
func symbol(f *os.FileInfo) (s string) {
switch {
case f.IsDirectory():
s = "/"
case f.IsFifo():
s = "|"
case f.IsSocket():
s = "="
case f.IsSymlink():
target, err := os.Readlink(f.Name)
Errhandler(err)
s = " -> " + target
}
return
}
示例8: getEntryTypeString
func getEntryTypeString(e *os.FileInfo) string {
if e.IsDirectory() {
return "/"
} else if e.IsBlock() {
return "<>"
} else if e.IsFifo() {
return ">>"
} else if e.IsSymlink() {
return "@"
} else if e.IsSocket() {
return "&"
} else if e.IsRegular() && (e.Mode&0001 == 0001) {
return "*"
}
return ""
}
示例9: createChild
// createChild() creates a child for given as FsNode as child of 'parent'. The
// resulting inode will have its lookupCount incremented.
func (me *FileSystemConnector) createChild(parent *Inode, name string, fi *os.FileInfo, fsi FsNode) (out *EntryOut) {
parent.treeLock.Lock()
defer parent.treeLock.Unlock()
child := fsi.Inode()
if child == nil {
child = parent.createChild(name, fi.IsDirectory(), fsi)
} else {
parent.addChild(name, child)
}
me.lookupUpdate(child)
out = parent.mount.fileInfoToEntry(fi)
out.Ino = child.nodeId
out.NodeId = child.nodeId
return out
}
示例10: walk
func walk(path string, f *os.FileInfo, v Visitor, errors chan<- os.Error) {
if !f.IsDirectory() {
v.VisitFile(path, f)
return
}
if !v.VisitDir(path, f) {
return // skip directory entries
}
list, err := readDir(path)
if err != nil {
if errors != nil {
errors <- err
}
}
for _, e := range list {
walk(Join(path, e.Name), e, v, errors)
}
}
示例11: findChild
func (me *pathInode) findChild(fi *os.FileInfo, name string, fullPath string) (out *pathInode) {
if fi.Ino > 0 {
unlock := me.RLockTree()
v := me.pathFs.clientInodeMap[fi.Ino]
if len(v) > 0 {
out = v[0].node
if fi.Nlink == 1 {
log.Println("Found linked inode, but Nlink == 1", fullPath)
}
}
unlock()
}
if out == nil {
out = me.createChild(fi.IsDirectory())
out.clientInode = fi.Ino
me.addChild(name, out)
}
return out
}
示例12: itemType
func itemType(fi *os.FileInfo) string {
if fi.IsDirectory() {
return "1"
}
name := fi.Name
switch {
case strings.HasPrefix(name, ".html"):
return "h"
case strings.HasPrefix(name, ".txt"):
return "0"
case strings.HasPrefix(name, ".gif"):
return "g"
case strings.HasPrefix(name, ".png"),
strings.HasPrefix(name, ".jpg"),
strings.HasPrefix(name, ".jpeg"):
// TODO(bradfitz): re-encode pngs to gifs :)
// For now, though:
return "I" // Image file of unspecified format. Client decides
// how to display. Often used for JPEG images
}
return "9" // binary file
}
示例13: isPkgDir
func isPkgDir(f *os.FileInfo) bool {
return f.IsDirectory() && len(f.Name) > 0 && f.Name[0] != '_'
}
示例14: main
func main() {
var rr *http.Response
var myreader multipart.Reader
syscall.Umask(0000)
if !parseME() {
os.Exit(1)
}
var requesturl string
requesturl = ("http://" + (*camera_ip) + ":" + strconv.Itoa(*camera_port) + "/mjpg/1/video.mjpg")
fmt.Println("request sent to " + requesturl)
rr, _, _ = http.Get(requesturl)
myreader, _ = MultipartReader(rr)
var p *multipart.Part
var curr_length int = 0
var templen int
var buff []byte
var s string
var m int
var info *os.FileInfo
var err os.Error
info, err = os.Lstat(*save_folder)
if err != nil {
fmt.Println("Folder " + (*save_folder) + " Is problematic")
fmt.Println(err.String())
os.Exit(1)
}
if !info.IsDirectory() {
fmt.Println("Folder " + (*save_folder) + " Is not a directory")
os.Exit(1)
}
var foldertime *time.Time = nil
var foldersecs int64
var folderstamp string
var tstamp_secs int64
var tstamp_nsecs int64
var msecs int64
var update bool
var foldername string
var imagename string
var mywriter *os.File
for i := 0; i < 1; {
p, _ = myreader.NextPart()
update = false
tstamp_secs, tstamp_nsecs, _ = os.Time()
if foldertime == nil {
foldertime = time.SecondsToLocalTime(tstamp_secs)
foldersecs = tstamp_secs
update = true
} else {
if tstamp_secs > foldersecs {
foldertime = time.SecondsToLocalTime(tstamp_secs)
foldersecs = tstamp_secs
update = true
}
}
if update {
folderstamp = strconv.Itoa64(foldertime.Year) + "_" +
strconv.Itoa(foldertime.Month) + "_" +
strconv.Itoa(foldertime.Day) + "_" +
strconv.Itoa(foldertime.Hour) + "_" +
strconv.Itoa(foldertime.Minute) + "_" +
strconv.Itoa(foldertime.Second)
foldername = (*save_folder) + "/" + (*camera_name) + "_" + folderstamp
err = os.Mkdir(foldername, 0700)
if err != nil {
fmt.Fprintf(os.Stderr, "error creating %s because : %s\n", foldername, err.String())
os.Exit(1)
}
}
templen, _ = strconv.Atoi(p.Header["Content-Length"])
if templen > curr_length {
curr_length = templen
buff = make([]byte, curr_length)
}
for counter := 0; counter < templen; {
m, _ = p.Read(buff[counter:templen])
counter += m
}
//.........这里部分代码省略.........
示例15: isPackageDir
func isPackageDir(fileInIt *os.FileInfo) bool {
return !fileInIt.IsDirectory() && utils.IsGoFile(fileInIt.Name)
}