當前位置: 首頁>>代碼示例>>Golang>>正文


Golang FileInfo.Name方法代碼示例

本文整理匯總了Golang中os.FileInfo.Name方法的典型用法代碼示例。如果您正苦於以下問題:Golang FileInfo.Name方法的具體用法?Golang FileInfo.Name怎麽用?Golang FileInfo.Name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在os.FileInfo的用法示例。


在下文中一共展示了FileInfo.Name方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Matches

func (p simplePattern) Matches(path string, fi os.FileInfo) bool {
	if p.matchDirOnly && !fi.IsDir() {
		return false
	}
	filename := fi.Name()
	return filename == p.content
}
開發者ID:Rican7,項目名稱:sift,代碼行數:7,代碼來源:gitignore.go

示例2: archiveFile

func archiveFile(fname string, cfg *conf.Config, rootStat os.FileInfo, fs os.FileInfo) (newname string, err error) {
	year := strconv.Itoa(fs.ModTime().Year())
	month := fs.ModTime().Month().String()

	archivePath := filepath.Join(cfg.ArchivePath(rootStat.Name()), year, month)
	err = os.MkdirAll(archivePath, rootStat.Mode())
	if err != nil && !os.IsExist(err) {
		return
	}

	zipPath := archivePath + ".zip"
	if util.FileExists(zipPath) {
		//unzip so we can archive the new file ... it will be rezipped later
		if err = util.Unzip(zipPath, archivePath); err != nil {
			return
		}
	}

	newname = filepath.Join(archivePath, fs.Name())
	if _, err = os.Stat(newname); err == nil {
		err = fmt.Errorf("A file of the same name already exists in the archive")
		return
	}
	err = os.Rename(fname, newname)

	return
}
開發者ID:jquag,項目名稱:kempt,代碼行數:27,代碼來源:archive.go

示例3: fileInfoNameFunc

func fileInfoNameFunc(fi os.FileInfo) string {
	name := fi.Name()
	if fi.IsDir() {
		name += "/"
	}
	return name
}
開發者ID:tw4452852,項目名稱:go-src,代碼行數:7,代碼來源:godoc.go

示例4: handleFile

func handleFile(sourceDirectory string, targetDirectory string,
	file os.FileInfo) {
	fn := filepath.Join(sourceDirectory, file.Name())
	logging.Log.Debug("filename=%s", fn)
	photo := photograph.New()
	err := photo.Load(fn)
	if err != nil {
		logging.Log.Error(err.Error())
	}
	logging.Log.Debug("%d EXIF tags", len(photo.ExifMap))
	for tag, value := range photo.ExifMap {
		fmt.Printf("%s\t%s\n", tag, value)
	}
	logging.Log.Debug("photo=%v", photo.OriginalFileName)
	logging.Log.Debug("targetDir=%v", targetDirectory)
	targetDirectory = getTargetDirectoryNameWithDate(photo.Time,
		targetDirectory)
	err = os.MkdirAll(targetDirectory, 0700)
	if err != nil {
		logging.Log.Error(err.Error())
	}
	s := strings.Replace(file.Name(), "_DSC", "", 1)
	s = strings.Replace(s, "DSC_", "", 1)
	ext := filepath.Ext(s)
	s = strings.Replace(s, ext, "", 1)
	ext = strings.ToLower(ext)
	logging.Log.Debug("ext=%s", ext)
	targetFile := fmt.Sprintf("%s_%s_%s%s", photo.Iso8601(), s,
		"makela_ari", ext)
	targetFile = filepath.Join(targetDirectory, targetFile)
	logging.Log.Debug("targetFile=%s", targetFile)
	ioutil.WriteFile(targetFile, photo.Data, 0600)
}
開發者ID:hauva69,項目名稱:photowalk,代碼行數:33,代碼來源:photowalk.go

示例5: walkSlideshow

func (show *Slideshow) walkSlideshow(localpath string, info os.FileInfo, err error) error {

	if err != nil {
		return err
	}

	if info.IsDir() {
		return nil
	}

	ext := filepath.Ext(localpath)
	ext = strings.ToLower(ext)

	if ext == ".jpg" {

		photo := new(SlideshowPhoto)
		photo.path = localpath
		photo.Photo = path.Join("/slideshow", info.Name())
		photo.Timestamp = info.ModTime() //info.ModTime().Format(time.RFC3339)

		show.Photos = append(show.Photos, photo)

	}

	return nil

}
開發者ID:crown-hill,項目名稱:goutils,代碼行數:27,代碼來源:server.go

示例6: parseFile

func (t *Templates) parseFile(path string, f os.FileInfo, err error) error {
	if err != nil {
		return err
	}

	ext := filepath.Ext(f.Name())
	if f.IsDir() || !t.check(ext) {
		return nil
	}

	file, err := os.Open(path)
	if err != nil {
		return err
	}
	defer file.Close()

	contents, err := ioutil.ReadAll(file)
	if err != nil {
		return err
	}

	subPath := strings.Replace(path, t.stripPrefix, "", 1)
	if strings.Contains(path, "/view/") || strings.Contains(path, "/views/") {
		t.views[subPath] = string(contents)
	} else {
		t.partials[subPath] = string(contents)
	}

	return nil
}
開發者ID:james-maloney,項目名稱:templates,代碼行數:30,代碼來源:templates.go

示例7: tarDir

func tarDir(srcBase, srcRelative string, tw *tar.Writer, fi os.FileInfo) (err error) {
	srcFull := srcBase + srcRelative
	fis, er := ioutil.ReadDir(srcFull)
	if er != nil {
		return er
	}

	for _, fi := range fis {
		if fi.IsDir() {
			tarDir(srcBase, srcRelative+"/"+fi.Name(), tw, fi)
		} else {
			tarFile(srcBase, srcRelative+"/"+fi.Name(), tw, fi)
		}
	}

	if len(srcRelative) > 0 {
		hdr, er := tar.FileInfoHeader(fi, "")
		if er != nil {
			return er
		}
		hdr.Name = srcRelative
		if er = tw.WriteHeader(hdr); er != nil {
			return er
		}
	}

	return nil
}
開發者ID:icsnju,項目名稱:apt-mesos,代碼行數:28,代碼來源:tar.go

示例8: 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

示例9: OnlyDir_TrailingSlash

func (t *GcsfuseTest) OnlyDir_TrailingSlash() {
	var err error
	var fi os.FileInfo

	// Mount only a single directory from the bucket, including a trailing slash.
	args := []string{
		"--only-dir",
		path.Dir(canned.ExplicitDirFile) + "/",
		canned.FakeBucketName,
		t.dir,
	}

	err = t.runGcsfuse(args)
	AssertEq(nil, err)
	defer unmount(t.dir)

	// It should be as if t.dir points into the bucket's first-level directory.
	entries, err := fusetesting.ReadDirPicky(t.dir)
	AssertEq(nil, err)

	AssertEq(1, len(entries))
	fi = entries[0]
	ExpectEq(path.Base(canned.ExplicitDirFile), fi.Name())
	ExpectEq(len(canned.ExplicitDirFile_Contents), fi.Size())
}
開發者ID:zfo,項目名稱:gcsfuse,代碼行數:25,代碼來源:gcsfuse_test.go

示例10: ToTempFile

// ToTempFile writes an action into a generated temporary file and returns its filename
func (a Action) ToTempFile() (filename string, err error) {
	var (
		data []byte
		fd   *os.File
		fi   os.FileInfo
	)
	data, err = json.Marshal(a)
	if err != nil {
		return
	}
	fd, err = ioutil.TempFile("", "migaction_")
	defer fd.Close()
	if err != nil {
		return
	}
	_, err = fd.Write(data)
	if err != nil {
		return
	}
	fi, err = fd.Stat()
	if err != nil {
		return
	}
	filename = fmt.Sprintf("%s/%s", os.TempDir(), fi.Name())
	return
}
開發者ID:jvehent,項目名稱:mig,代碼行數:27,代碼來源:action.go

示例11: 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

示例12: downloadsWalkFunc

func downloadsWalkFunc(fullPath string, Version string, fi2 os.FileInfo, err error, tp TaskParams, report Report, reportFilename, format string) error {
	if fi2.IsDir() || fi2.Name() == reportFilename {
		return nil
	}

	versionDir := filepath.Join(tp.OutDestRoot, tp.Settings.GetFullVersionName())
	relativePath := strings.Replace(fullPath, versionDir, "", -1)
	relativePath = strings.TrimPrefix(relativePath, "/")
	text := fi2.Name()
	if format == "markdown" {
		text = strings.Replace(text, "_", "\\_", -1)
	}
	category := GetCategory(relativePath)

	//log.Printf("Adding: %s", relativePath)
	download := Download{text, Version, relativePath}
	v, ok := report.Categories[category]
	var existing []Download
	if !ok {
		existing = []Download{}
	} else {
		existing = *v
	}

	existing = append(existing, download)
	report.Categories[category] = &existing
	//entryCount++
	return nil
}
開發者ID:yl10,項目名稱:goxc,代碼行數:29,代碼來源:downloads-page.go

示例13: refreshCache

func (fs *memFileSystem) refreshCache(path string, info os.FileInfo) (err error) {
	// Delete the file if fi is nil.
	if info == nil {
		fs.lock.Lock()
		delete(fs.cache, path)
		fs.lock.Unlock()
		return
	}

	// Create memory fileinfo and read contents.
	fi := &memFileInfo{
		name:    info.Name(),
		size:    info.Size(),
		mode:    info.Mode(),
		modTime: info.ModTime(),
		isDir:   info.IsDir(),
		path:    path,
		fs:      fs,
	}

	// Fill content of the file from disk.
	if !fi.isDir {
		fi.content, err = ioutil.ReadFile(path)
		if err != nil {
			return
		}
	}

	// Update cache and return.
	fs.lock.Lock()
	fs.cache[path] = fi
	fs.lock.Unlock()
	return
}
開發者ID:ranveerkunal,項目名稱:memfs,代碼行數:34,代碼來源:fs.go

示例14: shouldTraverse

// shouldTraverse reports whether the symlink fi should, found in dir,
// should be followed.  It makes sure symlinks were never visited
// before to avoid symlink loops.
func shouldTraverse(dir string, fi os.FileInfo) bool {
	path := filepath.Join(dir, fi.Name())
	target, err := filepath.EvalSymlinks(path)
	if err != nil {
		if !os.IsNotExist(err) {
			fmt.Fprintln(os.Stderr, err)
		}
		return false
	}
	ts, err := os.Stat(target)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return false
	}
	if !ts.IsDir() {
		return false
	}

	realParent, err := filepath.EvalSymlinks(dir)
	if err != nil {
		fmt.Fprint(os.Stderr, err)
		return false
	}
	realPath := filepath.Join(realParent, fi.Name())
	visitedSymlinks.Lock()
	defer visitedSymlinks.Unlock()
	if visitedSymlinks.m == nil {
		visitedSymlinks.m = make(map[string]struct{})
	}
	if _, ok := visitedSymlinks.m[realPath]; ok {
		return false
	}
	visitedSymlinks.m[realPath] = struct{}{}
	return true
}
開發者ID:zeebo,項目名稱:tools,代碼行數:38,代碼來源:fix.go

示例15: getRealName

// getRealName - gets the proper filename for sorting purposes
// Readdir() filters out directory names without separators, add
// them back for proper sorting results.
func getRealName(info os.FileInfo) string {
	if info.IsDir() {
		// Make sure directory has its end separator.
		return info.Name() + string(os.PathSeparator)
	}
	return info.Name()
}
開發者ID:AcalephStorage,項目名稱:minio,代碼行數:10,代碼來源:fs-utils.go


注:本文中的os.FileInfo.Name方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。