当前位置: 首页>>代码示例>>Golang>>正文


Golang FileInfo.IsDir方法代码示例

本文整理汇总了Golang中os.FileInfo.IsDir方法的典型用法代码示例。如果您正苦于以下问题:Golang FileInfo.IsDir方法的具体用法?Golang FileInfo.IsDir怎么用?Golang FileInfo.IsDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os.FileInfo的用法示例。


在下文中一共展示了FileInfo.IsDir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: shouldRead

func (f *Filesystem) shouldRead(filePath string, fi os.FileInfo) (bool, error) {
	if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
		link, err := filepath.EvalSymlinks(filePath)
		if err != nil {
			jww.ERROR.Printf("Cannot read symbolic link '%s', error was: %s", filePath, err)
			return false, nil
		}
		linkfi, err := os.Stat(link)
		if err != nil {
			jww.ERROR.Printf("Cannot stat '%s', error was: %s", link, err)
			return false, nil
		}
		if !linkfi.Mode().IsRegular() {
			jww.ERROR.Printf("Symbolic links for directories not supported, skipping '%s'", filePath)
		}
		return false, nil
	}

	if fi.IsDir() {
		if f.avoid(filePath) || isNonProcessablePath(filePath) {
			return false, filepath.SkipDir
		}
		return false, nil
	}

	if isNonProcessablePath(filePath) {
		return false, nil
	}
	return true, nil
}
开发者ID:yanwushuang,项目名称:pango,代码行数:30,代码来源:filesystem.go

示例2: mountVolumes

func (daemon *Daemon) mountVolumes(container *Container) error {
	mounts, err := daemon.setupMounts(container)
	if err != nil {
		return err
	}

	for _, m := range mounts {
		dest, err := container.GetResourcePath(m.Destination)
		if err != nil {
			return err
		}

		var stat os.FileInfo
		stat, err = os.Stat(m.Source)
		if err != nil {
			return err
		}
		if err = fileutils.CreateIfNotExists(dest, stat.IsDir()); err != nil {
			return err
		}

		opts := "rbind,ro"
		if m.Writable {
			opts = "rbind,rw"
		}

		if err := mount.Mount(m.Source, dest, "bind", opts); err != nil {
			return err
		}
	}

	return nil
}
开发者ID:RockaLabs,项目名称:docker,代码行数:33,代码来源:container_unix.go

示例3: bumpWalk

// bumpWalk walks the third_party directory and bumps all of the packages that it finds.
func bumpWalk(path string, info os.FileInfo, err error) error {
	if err != nil {
		return nil
	}

	// go packages are always directories
	if info.IsDir() == false {
		return nil
	}

	parts := strings.Split(path, srcDir()+"/")
	if len(parts) == 1 {
		return nil
	}

	pkg := parts[1]

	if validPkg(pkg) == false {
		return nil
	}

	bump(pkg, "")

	return nil
}
开发者ID:robyoung,项目名称:performance-datastore,代码行数:26,代码来源:third_party.go

示例4: walk

// Walk recursively iterates over all files in a directory and processes any
// file that imports "github.com/boltdb/raw".
func walk(path string, info os.FileInfo, err error) error {
	traceln("walk:", path)

	if info == nil {
		return fmt.Errorf("file not found: %s", err)
	} else if info.IsDir() {
		traceln("skipping: is directory")
		return nil
	} else if filepath.Ext(path) != ".go" {
		traceln("skipping: is not a go file")
		return nil
	}

	// Check if file imports boltdb/raw.
	if v, err := importsRaw(path); err != nil {
		return err
	} else if !v {
		traceln("skipping: does not import raw")
		return nil
	}

	// Process each file.
	if err := process(path); err != nil {
		return err
	}

	return nil
}
开发者ID:jmptrader,项目名称:raw,代码行数:30,代码来源:main.go

示例5: fileInfoNameFunc

func fileInfoNameFunc(fi os.FileInfo) string {
	name := fi.Name()
	if fi.IsDir() {
		name += "/"
	}
	return name
}
开发者ID:tw4452852,项目名称:go-src,代码行数:7,代码来源:godoc.go

示例6: loadMessageFile

// Load a single message file
func loadMessageFile(path string, info os.FileInfo, osError error) error {
	if osError != nil {
		return osError
	}
	if info.IsDir() {
		return nil
	}

	if matched, _ := regexp.MatchString(messageFilePattern, info.Name()); matched {
		if config, error := parseMessagesFile(path); error != nil {
			return error
		} else {
			locale := parseLocaleFromFileName(info.Name())

			// If we have already parsed a message file for this locale, merge both
			if _, exists := messages[locale]; exists {
				messages[locale].Merge(config)
				TRACE.Printf("Successfully merged messages for locale '%s'", locale)
			} else {
				messages[locale] = config
			}

			TRACE.Println("Successfully loaded messages from file", info.Name())
		}
	} else {
		TRACE.Printf("Ignoring file %s because it did not have a valid extension", info.Name())
	}

	return nil
}
开发者ID:revel,项目名称:revel,代码行数:31,代码来源:i18n.go

示例7: walkLeaf

func (wft *walkFileTree) walkLeaf(fpath string, fi os.FileInfo, err error) error {
	if err != nil {
		return err
	}

	if fpath == outputP {
		return nil
	}

	if fi.IsDir() {
		return nil
	}

	if ssym && fi.Mode()&os.ModeSymlink > 0 {
		return nil
	}

	name := wft.virPath(fpath)

	if wft.allfiles[name] {
		return nil
	}

	if added, err := wft.wak.compress(name, fpath, fi); added {
		if verbose {
			fmt.Printf("Compressed: %s\n", name)
		}
		wft.allfiles[name] = true
		return err
	} else {
		return err
	}
}
开发者ID:Linvas,项目名称:ant,代码行数:33,代码来源:pack.go

示例8: procesImage

func procesImage(path string, f os.FileInfo, err error) error {
	if f.IsDir() {
		return nil
	}

	log.Debugf("Processing %s", path)

	extension := filepath.Ext(f.Name())
	if !isSupportPhotoType(strings.ToLower(extension)) {
		log.Warnf("%s's file type %s is unsupported", path, extension)
		return nil
	}

	reader := exif.New()

	err = reader.Open(path)
	if err != nil {
		log.Fatal(err)
	}

	str := fmt.Sprintf("%s", reader.Tags["Date and Time"])
	t := f.ModTime()

	if len(str) == 0 {
		log.Warnf("Date and Time EXIF tag missing for %s", path)
	} else {
		layout := "2006:01:02 15:04:05"
		t, err = time.Parse(layout, str)
		if err != nil {
			log.Fatal(err)
		}
	}

	newDir := fmt.Sprintf("%s/%4d/%02d/%02d", destPath, t.Year(), t.Month(), t.Day())

	err = os.MkdirAll(newDir, 0777)
	if err != nil {
		log.Fatal(err)
	}

	newFile := fmt.Sprintf("%s/%s", newDir, f.Name())

	if mode == "move" {
		log.Debugf("Moving %s %s", path, newFile)
		err = os.Rename(path, newFile)
	} else {
		if _, err := os.Stat(newFile); err == nil {
			log.Warnf("Photo %s already exists", newFile)
		} else {
			log.Debugf("Copying %s %s", path, newFile)
			err = copyFile(path, newFile)
		}
	}

	if err != nil {
		log.Fatal(err)
	}

	return nil
}
开发者ID:ashmckenzie,项目名称:photoman,代码行数:60,代码来源:main.go

示例9: walkdir

func walkdir(path string, f os.FileInfo, err error) error {
	fmt.Printf("Visited: %s\n", path)
	if f.IsDir() == false {
		output = inspectfile(path, output)
	}
	return nil
}
开发者ID:fdegui15,项目名称:dockerif,代码行数:7,代码来源:inspectsFile.go

示例10: deriveFolderName

func deriveFolderName(path string, info os.FileInfo) string {
	if info.IsDir() {
		return path
	} else {
		return filepath.Dir(path)
	}
}
开发者ID:npadmana,项目名称:goconvey,代码行数:7,代码来源:walk_step.go

示例11: visit

// visit a file path
// if the file is a .pb.go (protobuf file), call the parse function and add result to output
func visit(currentPath string, f os.FileInfo, err error) error {
	fmt.Printf("Visited: %s\n", currentPath)
	if !f.IsDir() {
		var fileName = f.Name()
		var strLen = len(fileName)
		if strLen >= len(DEFAULT_EXTENSION) && fileName[strLen-len(DEFAULT_EXTENSION):strLen] == DEFAULT_EXTENSION {
			absPath, err1 := filepath.Abs(currentPath)
			if err1 == nil {
				importPath := filepath.Dir(absPath)
				if importPath[0:len(goPath)] == goPath {
					importPath = importPath[len(goPath):len(importPath)]
				}
				srcIndex := strings.Index(importPath, SRC_DIR)
				importPath = importPath[srcIndex+len(SRC_DIR) : len(importPath)]
				fmt.Printf("file path from go path: %d %s\n", srcIndex, importPath)

				result := parseProtobufFile(absPath, importPath)

				if !output.ImportPath[result.ImportPath] {
					// add import path to output
					output.ImportPath[result.ImportPath] = true
				}
				for key, dataType := range result.Types {
					if _, ok := output.Types[key]; !ok {
						output.Types[key] = dataType
					}
				}
			}
		}
	}
	return err
}
开发者ID:botaydotcom,项目名称:GoMessagingTestFrameWork,代码行数:34,代码来源:generateMapCode.go

示例12: StreamFile

// StreamFile streams a file or directory entry into StreamArchive.
func (s *StreamArchive) StreamFile(relPath string, fi os.FileInfo, data []byte) error {
	if fi.IsDir() {
		fh, err := zip.FileInfoHeader(fi)
		if err != nil {
			return err
		}
		fh.Name = relPath + "/"
		if _, err = s.Writer.CreateHeader(fh); err != nil {
			return err
		}
	} else {
		fh, err := zip.FileInfoHeader(fi)
		if err != nil {
			return err
		}
		fh.Name = filepath.Join(relPath, fi.Name())
		fh.Method = zip.Deflate
		fw, err := s.Writer.CreateHeader(fh)
		if err != nil {
			return err
		} else if _, err = fw.Write(data); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:RouGang,项目名称:gopm,代码行数:27,代码来源:stream.go

示例13: Ignore

// Ignore evalutes the file at the given path, and returns true if it should be ignored.
//
// Ignore evaluates path against the rules in order. Evaluation stops when a match
// is found. Matching a negative rule will stop evaluation.
func (r *Rules) Ignore(path string, fi os.FileInfo) bool {
	for _, p := range r.patterns {
		if p.match == nil {
			log.Printf("ignore: no matcher supplied for %q", p.raw)
			return false
		}

		// For negative rules, we need to capture and return non-matches,
		// and continue for matches.
		if p.negate {
			if p.mustDir && !fi.IsDir() {
				return true
			}
			if !p.match(path, fi) {
				return true
			}
			continue
		}

		// If the rule is looking for directories, and this is not a directory,
		// skip it.
		if p.mustDir && !fi.IsDir() {
			continue
		}
		if p.match(path, fi) {
			return true
		}
	}
	return false
}
开发者ID:runseb,项目名称:helm,代码行数:34,代码来源:rules.go

示例14: list

func list(path string, info os.FileInfo, node *fsNode, n *int) error {
	if (!info.IsDir() && !info.Mode().IsRegular()) || strings.HasPrefix(info.Name(), ".") {
		return errors.New("Non-regular file")
	}
	(*n)++
	if (*n) > fileNumberLimit {
		return errors.New("Over file limit") //limit number of files walked
	}
	node.Name = info.Name()
	node.Size = info.Size()
	node.Modified = info.ModTime()
	if !info.IsDir() {
		return nil
	}
	children, err := ioutil.ReadDir(path)
	if err != nil {
		return fmt.Errorf("Failed to list files")
	}
	node.Size = 0
	for _, i := range children {
		c := &fsNode{}
		p := filepath.Join(path, i.Name())
		if err := list(p, i, c, n); err != nil {
			continue
		}
		node.Size += c.Size
		node.Children = append(node.Children, c)
	}
	return nil
}
开发者ID:Zarloc,项目名称:cloud-torrent,代码行数:30,代码来源:server_files.go

示例15: includeFolders

func (self *Watcher) includeFolders(path string, info os.FileInfo, err error) error {
	if info.IsDir() {
		log.Println("Including:", path)
		self.watched[path] = contract.NewPackage(path)
	}
	return nil
}
开发者ID:newobject,项目名称:goconvey,代码行数:7,代码来源:watcher.go


注:本文中的os.FileInfo.IsDir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。