GoLang文件增删遍历基本操作
先学一学GO语言实用的一面。
package main
import (
"path/filepath"
"flag"
"os"
"fmt"
)
func getFileList(path string) {
err := filepath.Walk(path, func(path string, f os.FileInfo, err error) error {
if (f == nil) {return err}
if f.IsDir() {return nil}
println(path)
return nil
})
if err != nil {
fmt.Printf("filepath.Walk() returned %v\n", err)
}
}
func main() {
userFile := "test.txt"
fout, err := os.Create(userFile)
defer fout.Close()
if err != nil {
fmt.Println(userFile, err)
return
}
for i:=0; i<10; i++ {
fout.WriteString("Just a test!\r\n")
fout.Write([]byte("Just a array string!\r\n"))
}
fin, err := os.Open(userFile)
defer fin.Close()
if err != nil {
fmt.Println(userFile, err)
return
}
buf := make([]byte, 1024)
for {
n, _ := fin.Read(buf)
if 0 == n {
break
}
os.Stdout.Write(buf[:n])
}
flag.Parse()
root := flag.Arg(0)
getFileList(root)
}
GoLang文件增删遍历基本操作的更多相关文章
- C# 文件的一些基本操作(转)//用C#读写ini配置文件
C# 文件的一些基本操作 2009-07-19 来自:博客园 字体大小:[大 中 小] 摘要:介绍C#对文件的一些基本操作,读写等. using System;using System.IO;us ...
- lua使用io.open跨平台文件夹遍历匹配查找
-- Desc :实现在LUA_PATH中的lua文件中遍历寻找没用到PNG_PATH路径下的png图片,并将其打印出来. -- Date :12:49:28 2014-09-04 1 print(& ...
- python学习笔记(六)文件夹遍历,异常处理
python学习笔记(六) 文件夹遍历 1.递归遍历 import os allfile = [] def dirList(path): filelist = os.listdir(path) for ...
- Golang文件IO 一
Golang文件IO 一 文件IO编程最基本.最常用的就属读写文件操作了.ioutil包实现了一些IO实用功能,其中就包括非常简捷.好用的文件读取功能. ioutil包有7个函数1个变量: var D ...
- vc++基础班[23]---文件夹的基本操作
①.文件夹的创建:CreateDirectory ※※※ 注意:此函数只能创建一层目录,比如想在 C 盘下的 Temp 目录下创建新目录为:123 那么前提是 Temp 这个目录存在才可以! ...
- golang文件传输服务
续上篇,本篇介绍一个完整的golang文件传输服务器. 完整的代码可以看服务器,客户端 网络使用的框架如上篇介绍,这里就不再复述. 首先定义3个命令码: const ( request_file = ...
- HALCON初步:文件夹遍历,文件筛选,文件名拆分,图片读取及保存
[1]文件夹遍历 list_image_files ( : : ImageDirectory, Extensions, Options : ImageFiles) ImageDirectory: 文件 ...
- GOLANG文件拷贝
GOLANG文件拷贝 在Golang中,使用系统自带函数io.Copy() 如: srcFile := "C:/Users/Wisdom/Desktop/Wisdompic.png" ...
- goLang文件遍历
package main import ( "fmt" "io/ioutil" "os" "path/filepath&q ...
随机推荐
- Codeforces Gym 101138 G. LCM-er
Description 在 \([a,b]\) 之间选择 \(n\) 个数 (可以重复) ,使这 \(n\) 个数的最小公倍数能被 \(x\) 整除,对 \(10^9+7\) 取膜. \(1\leqs ...
- 调用pyxmpp库PyQt编程打包成exe文件出错
pyxmpp库内resolver.py内getaddrinfo获取Openfire服务器地址出错
- Python类的特点 (3) :静态方法与类方法
Python中的方法有4种: 1)模块中的全局方法,不属于任何类,用"模块名.方法名"形式调用. 2)类中定义的实例方法,也被称为绑定方法(Bound method),这种方法的第 ...
- POJ 1661
http://poj.org/problem?id=1661 这是一道DP的题目,求最优解 上面的这一个题是对于那个重左边开始上的函数的解释 题目要求的是从最高掉下来的小时间,那么我们就可以求从最低处 ...
- robotFramework——截屏
测试执行过程中进行截屏并且保存,是任何一款自动化测试工具或者框架必备的功能.那么Robotframework如何进行截屏呢?Robotframework提供了一个“Screenshot”库. 使 ...
- ios NSNotificationCenter 收到通知后的执行线程
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Notifications/Articles/Thread ...
- ios swfit 由继承UIButton了解类的构造方法
最近需要建立UIButton的子类. 先看一看swfit中继承父类构造方法的条件: Rule1 1“If your subclass doesn’t define any designated ini ...
- FastReport报表对象介绍一:“Text”对象
FastReport中文网 http://www.fastreportcn.com/Article/70.html ------------------------------------------ ...
- [Android]如何获取当前用户设置的时区
方法:TimeZone.getDefault().getDisplayName(true, TimeZone.SHORT);获取的值如GMT+08:00,GMT-04:00,EDT 另附:国家码查询 ...
- CentOS搭建svn服务器支持https访问
在CentOS6.3 64位机器上配置SVN服务器,并设置只允许HTTPS连接,可以配置多个repos源,每个源都拥有自己的组和成员,用于权限控制. 安装相关软件 Apache yum install ...