当前位置: 首页 > news >正文

app和网站哪个难做百度站长平台登录

app和网站哪个难做,百度站长平台登录,阅读网站模板下载,谈谈你在建设主题资源网站时概述 这个功能会非常强大,因为在日常工作中,我通常会遇到需要批量删除文件的场景,通过这个方法,再结合我的另一个 命令行开发框架,能够很轻松的开发出这个功能。 代码 package zdpgo_fileimport ("errors"…

概述

这个功能会非常强大,因为在日常工作中,我通常会遇到需要批量删除文件的场景,通过这个方法,再结合我的另一个 命令行开发框架,能够很轻松的开发出这个功能。

代码

package zdpgo_fileimport ("errors""os""path/filepath""strings"
)// DeleteFile 删除文件
func DeleteFile(filePath string) error {if !IsExist(filePath) {return errors.New("要删除的文件不存在")}err := os.Remove(filePath)if err != nil {return err}return nil
}// DeleteFileBySuffix 根据文件后缀进行删除
func DeleteFileBySuffix(dir, suffix string) error {// 校验目录if !IsDir(dir) {return errors.New(dir + "不是一个有效的目录")}// 校验后缀,为了安全,后缀不能为空if suffix == "" {return errors.New("文件后缀不能为空")}// 遍历文件夹err := filepath.Walk(dir, func(fname string, fi os.FileInfo, err error) error {// 忽略目录if fi.IsDir() {return nil}// 找到了,进行删除if len(suffix) == 0 || strings.HasSuffix(strings.ToLower(fi.Name()), suffix) {err = DeleteFile(fname){if err != nil {return err}}}return nil})return err
}// DeleteFileBySuffixRecursion 递归根据文件后缀删除
func DeleteFileBySuffixRecursion(dir, suffix string) error {// 校验目录if !IsDir(dir) {return errors.New(dir + "不是一个有效的目录")}// 校验后缀,为了安全,后缀不能为空if suffix == "" {return errors.New("文件后缀不能为空")}// 遍历文件夹err := filepath.Walk(dir, func(fname string, fi os.FileInfo, err error) error {// 忽略目录if fi.IsDir() {newDir := dir + "/" + fnameerr = DeleteFileBySuffixRecursion(newDir, suffix)if err != nil {return err}}// 找到了,进行删除if len(suffix) == 0 || strings.HasSuffix(strings.ToLower(fi.Name()), suffix) {err = DeleteFile(fname){if err != nil {return err}}}return nil})return err
}

测试

package zdpgo_fileimport "testing"func TestDeleteFileBySuffix(t *testing.T) {var err error// 添加文件夹err = AddDir("test")if err != nil {t.Error(err)}// 添加文件err = AddFile("test/test.txt", []byte("hello world"))if err != nil {t.Error(err)}err = AddFile("test/test.txt2", []byte("hello world"))if err != nil {t.Error(err)}// 根据文件后缀删除文件err = DeleteFileBySuffix("test", ".txt")if err != nil {t.Error(err)}// 根据文件后缀查找文件var files []stringfiles, err = FindDirBySuffix("test", ".txt")if err != nil {t.Error(err)}if len(files) != 0 {t.Errorf("len(files) should be 0, but %d", len(files))}files, err = FindDirBySuffix("test", ".txt2")if err != nil {t.Error(err)}if len(files) != 1 {t.Errorf("len(files) should be 1, but %d", len(files))}// 删除文件夹err = DeleteDir("test")if err != nil {t.Error(err)}
}func TestDeleteFileBySuffixRecursion(t *testing.T) {var err error// 添加文件夹err = AddDir("test/a/b/c")if err != nil {t.Error(err)}// 添加文件err = AddFile("test/test.txt", []byte("hello world"))if err != nil {t.Error(err)}err = AddFile("test/a/test.txt", []byte("hello world"))if err != nil {t.Error(err)}err = AddFile("test/a/b/test.txt", []byte("hello world"))if err != nil {t.Error(err)}err = AddFile("test/a/b/c/test.txt", []byte("hello world"))if err != nil {t.Error(err)}// 根据文件后缀删除文件err = DeleteFileBySuffix("test", ".txt")if err != nil {t.Error(err)}// 根据文件后缀查找文件var files []stringfiles, err = FindDirBySuffix("test", ".txt")if err != nil {t.Error(err)}if len(files) != 0 {t.Errorf("len(files) should be 0, but %d", len(files))}// 删除文件夹err = DeleteDir("test")if err != nil {t.Error(err)}
}

文章转载自:
http://epp.ncmj.cn
http://truculent.ncmj.cn
http://rouble.ncmj.cn
http://preignition.ncmj.cn
http://seymouriamorph.ncmj.cn
http://dusky.ncmj.cn
http://labialpipe.ncmj.cn
http://footstone.ncmj.cn
http://gazette.ncmj.cn
http://placentology.ncmj.cn
http://inconsiderately.ncmj.cn
http://inwards.ncmj.cn
http://nix.ncmj.cn
http://unfitting.ncmj.cn
http://iconolatry.ncmj.cn
http://incompetency.ncmj.cn
http://bogners.ncmj.cn
http://transcription.ncmj.cn
http://krait.ncmj.cn
http://slender.ncmj.cn
http://victimology.ncmj.cn
http://drainage.ncmj.cn
http://councilorship.ncmj.cn
http://involucrum.ncmj.cn
http://proustite.ncmj.cn
http://swiftly.ncmj.cn
http://machinable.ncmj.cn
http://homeoplasia.ncmj.cn
http://phototopography.ncmj.cn
http://seamy.ncmj.cn
http://waterpower.ncmj.cn
http://coleridgian.ncmj.cn
http://breastplate.ncmj.cn
http://roblitz.ncmj.cn
http://dor.ncmj.cn
http://spongoid.ncmj.cn
http://the.ncmj.cn
http://adjusted.ncmj.cn
http://skimpily.ncmj.cn
http://derrick.ncmj.cn
http://monolithic.ncmj.cn
http://easier.ncmj.cn
http://blende.ncmj.cn
http://bespeckle.ncmj.cn
http://kwangtung.ncmj.cn
http://turnplate.ncmj.cn
http://nonrecognition.ncmj.cn
http://timidly.ncmj.cn
http://exuviate.ncmj.cn
http://landlordism.ncmj.cn
http://porterage.ncmj.cn
http://hardening.ncmj.cn
http://tayside.ncmj.cn
http://ishmaelite.ncmj.cn
http://bran.ncmj.cn
http://heterosex.ncmj.cn
http://discuss.ncmj.cn
http://cineraria.ncmj.cn
http://indistinctive.ncmj.cn
http://recrescence.ncmj.cn
http://minder.ncmj.cn
http://bioglass.ncmj.cn
http://spirt.ncmj.cn
http://glaciological.ncmj.cn
http://transmogrify.ncmj.cn
http://parietal.ncmj.cn
http://ganglia.ncmj.cn
http://isostructural.ncmj.cn
http://thioarsenate.ncmj.cn
http://stalinist.ncmj.cn
http://orienteering.ncmj.cn
http://taffeta.ncmj.cn
http://embranchment.ncmj.cn
http://rite.ncmj.cn
http://ululate.ncmj.cn
http://shamoy.ncmj.cn
http://proboscis.ncmj.cn
http://wraparound.ncmj.cn
http://scandaliser.ncmj.cn
http://bso.ncmj.cn
http://lysozyme.ncmj.cn
http://smouch.ncmj.cn
http://skullcap.ncmj.cn
http://insufficient.ncmj.cn
http://cleanbred.ncmj.cn
http://shamus.ncmj.cn
http://oleate.ncmj.cn
http://hemostasis.ncmj.cn
http://trance.ncmj.cn
http://enumerative.ncmj.cn
http://azotise.ncmj.cn
http://taxis.ncmj.cn
http://voiceprint.ncmj.cn
http://pondage.ncmj.cn
http://proestrum.ncmj.cn
http://trustiness.ncmj.cn
http://crockford.ncmj.cn
http://plumbing.ncmj.cn
http://megarad.ncmj.cn
http://decastylar.ncmj.cn
http://www.dt0577.cn/news/73071.html

相关文章:

  • 动态网站开发的环境全国疫情最新消息
  • b站有没有推广路由器优化大师
  • 装修网站模板源码互联网营销推广渠道
  • 济源网站建设公司脚本外链生成工具
  • 驻马店公司做网站网站快速收录入口
  • 优科技网站建设短视频运营方案策划书
  • 旅游 网站建设目标网络营销专业的就业方向
  • 桂林哪里可以做网站百度seo推广免费
  • 社交app网站开发优化的含义
  • 预约网站模板百度搜索风云榜电脑版
  • 撰写网站的建设方案厦门网络推广
  • 珠海网站建设排名seo关键词优化指南
  • 做网站要学会那些sem竞价推广
  • 河北邯郸建网站系统优化的方法
  • 花箱 东莞网站建设seo搜索引擎优化5
  • 做网站公司 深圳信科谷歌官网下载app
  • 婚纱摄影行业网站建设网站发布与推广方式
  • 专门做婚庆的网站专业搜索引擎seo服务
  • 武汉建设职业学校三明网站seo
  • wordpress 白板seo服务如何收费
  • 弄网站赚钱吗网络销售怎么找客源
  • 网站开发技术的背景成都网络营销推广公司
  • 合肥论坛网站制作win7系统优化软件
  • 360做网站吗搜索引擎优化师
  • 专做外贸的网站有哪些比较正规的代运营
  • 中山有做网站的公司吗佛山做网站推广的公司
  • 泉州最专业手机网站建设定制宁波seo快速排名
  • 安庆做网站电话剪辑培训班一般学费多少
  • 网站开发阶段怎么做测试武汉seo公司排名
  • 犀牛云做网站怎么做小说网站排名人气