当前位置: 首页 > 工具软件 > GFile > 使用案例 >

tensorflow gfile文件操作

关志
2023-12-01

一、gfile模块:对文件进行操作

defined in tensorflow/python/lib/io/file_io.py

二:相关函数:

1. tf.gfile.Copy(oldpath, newpath, overwrite=False)

功能:从旧地址拷贝到新地址(Copies data from oldpath to newpath)

2. tf.gfile.DeleteRecursively(diename) recursively:递归地

功能:以递归的方式删除dirname下的所有内容(Deletes everything under the dirname recursively)

3. tf.gfile.Exists(filename)

功能:确定路径是否存在(Determines whether a path exists or not)

4. tf.gfile.Glop(filename)

功能:返回与给定模式匹配的文件列表(Returns a list of files that match the given pattern(s))

5. tf.gfile.IsDirectory(dirname)

功能:返回路径是否是目录(Returns whether the path is a directory or not)

6. tf.gfile.ListDirectory(dirname)

功能:返回目录中包含的条目列表。该列表按任意顺序排列。它不包含特殊条目'.' and '..'。(Returns a list of entries contained a directory)

returns: [filename1, filename2, ..., filenameN] as strings

7. tf.gfile.MakeDirs(dirname)

功能:创建目录和所有父/中间目录。如果dirname已存在且可写,则成功(Creates a directory and all parent/intermediate directories)

8. tf.gfile.MkDir(dirname)

功能:创建名为dirname的目录(Creates a directory with the name 'dirname')

和MakeDirs却别:MakeDirs是创建一连串的目录比如/data/sub1/;MkDir则是创建一个目录,比如/data/

9. tf.gfile.Remove(filename)

功能:删除位于'filename'的文件(Deletes the file located at 'filename')

10. tf.gfile.Rename(oldname, newname, overwrite=False)

功能:重命名或移动文件/目录(Rename or move a file / dirctory)

Args:

· overwrite: boolean,如果为False,则newname被现有文件占用是错误的(boolean, if false it is an error for newname to be occupied by an exiting file)

11. tf.gfile.Stat(filename)

功能:返回给定路径的文件统计信息(Returns file statistics for a given path)

Returns: FileStatistics 结构,包含有关路径信息(FileStatistics struct that contains information about the path)

12. tf.gfile.Walk(top, in_order=True)

功能:目录的递归目录生成器(Recursive directory tree generator for directories)

Args:

· top:string,a Nirectory name

· in_order:bool, Traverse(遍历) in order if True, post order if False

 类似资料: