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 ...
随机推荐
- Java获取新浪微博cookies
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.F ...
- ajax给全局变量赋值问题解决
$.ajax({ type: "post", //以post方式与后台沟通 url: "./php/chartAjax.php", //与此php页面沟通 da ...
- $_request,$post,$get的三者区别和特点
一.$_request与$_post.$_get的区别和特点 $_REQUEST[]具用$_POST[] $_GET[]的功能,但是$_REQUEST[]比较慢.通过post和get方法提交的所有数据 ...
- 初识hibernate小案例
使用hibernate前需要导入相关JAR包. 1.它可以接受词文法语言描述,并能产生识别这些语言的语句的程序 2.是一个Java的XML API,类似于jdom,用来读写XML文件的 3.支持注解配 ...
- 1.3---字符串重新排列后是否能够变成另一个字符串(CC150)
import java.util.*; public class Same { public boolean checkSam(String str1, String str2) { // write ...
- peewee Model.get的复杂查询
(a | b )&c 官方文档没有具体讲到,又没有太多时间来看源码.经过尝试, (a | b) and c (a or b) and c 都是可以的. 而 (a | b) &c 是不 ...
- sublime 支持php语法错误提示的插件
求一个好用的sublime 支持php语法错误提示的插件.我装过sublimelinter,但是有时候出现错误也不会提示. 可以试试http://cs.sensiolabs.org/ 这个看哦它有对应 ...
- iOS开源App整理
http://duxinfeng.com/2015/07/14/iOS%E5%BC%80%E6%BA%90App%E6%95%B4%E7%90%86/ http://blog.csdn.net/dux ...
- mybatis Result Maps collection already contains value for com.ebways.dictionary.dao.impl.PtInfoDaoImpl.beanMap
java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.conte ...
- Appium 客户端库 API
## Appium 客户端库 Appium 有对应以下语言的客户端库: 语言 | 代码 :--|--:[Ruby][rubygems] | [GitHub](https://github.com/ap ...