遍历一个目录下的所有文件

首先我们获取用户文档目录路径

 let manager = FileManager.default
let urlForDocument = manager.urls(for: .documentDirectory, in:.userDomainMask)
let url = urlForDocument[] as URL
print("---------->\(url)")

打印结果:

---------->file:///Users/huanggang/Library/Developer/CoreSimulator/Devices/7B9AE7A4-4838-495B-964D-560DF760F7E1/data/Containers/Data/Application/70D8DA8D-4FEF-4715-B82E-0F40C1BC1B78/Documents/

深度遍历,会递归遍历子文件夹

 let enumeratorAtPath = manager.enumerator(atPath: url.path)
enumeratorAtPath?.skipDescendants() //跳过递归到最近获得的子目录
print("enumeratorAtPath: \(enumeratorAtPath?.allObjects)")

打印结果:

enumeratorAtPath: Optional([])

参考:文件夹操作

 

文件、文件夹操作(I)的更多相关文章

  1. [No000083]文件与文件夹操作

    #region Folder option 文件夹操作 /// <summary> /// 指定目录是否存在 /// </summary> /// <param name ...

  2. PHP 文件夹操作「复制、删除、查看大小」递归实现

    PHP虽然提供了 filesize.copy.unlink 等文件操作的函数,但是没有提供 dirsize.copydir.rmdirs 等文件夹操作的函数(rmdir也只能删除空目录).所以只能手动 ...

  3. C# 文件和文件夹操作

    一.文件操作 1.File类的常用静态方法: void AppendAllText(string path, string contents),将文本contents附加到文件path中 bool E ...

  4. Windows Store App 用户库文件夹操作

    上面介绍了与用户库文件有关的操作,包括创建.读写等,下面将介绍与用户库文件夹相关的操作. 与文件操作一样,想要对用户库文件夹进行操作,需要首先获取用户库的相应位置,获取的方法上面已经介绍过了,这里不再 ...

  5. .Net文件*夹*操作

    一.文件夹操作 Directory类,DirectoryInfo类.使用using System.IO命名空间 (一)创建文件夹 方法一: private string path = @"F ...

  6. iOS开发——Swift篇&文件,文件夹操作

    文件,文件夹操作   ios开发经常会遇到读文件,写文件等,对文件和文件夹的操作,这时就可以使用NSFileManager,NSFileHandle等类来实现. 下面总结了各种常用的操作:   1,遍 ...

  7. Python的文件与文件夹操作

    Python的文件与文件夹操作 Python OS模块 1.重命名:os.rename(old, new) 2.删除:os.remove(file) 3.列出目录下的文件 :os.listdir(pa ...

  8. linux文件夹操作(及模糊搜索)

    mkdir   文件夹名称    :创建文件夹 touch  文件名称       : 创建文件 给文件夹或文件授权 chmod -R 777 文件夹名称   : 递归给文件夹授读写执行权限 chmo ...

  9. python 文件及文件夹操作

    python 文件.目录操作(新增.移动.删除等) python 文件夹与文件操作 mport string, os, sys dir = '/var' print '----------- no s ...

  10. linux —— 学习笔记(文件、文件夹操作)

    目录:1.常用的文件文件夹操作 2.文件属性的设置 1.常用的文件文件夹操作 mkdir  创建文件夹 -p 如果指定 a/b/c 时 a .b 不存在,一起创建出来 cp       复制文件或文件 ...

随机推荐

  1. go get 的使用

    1.设置环境变量export GOPATH=/f/go_work2 2.go get github.com/xx

  2. js实现字符串格式的日期加一天

    参考使用的连接:https://blog.csdn.net/hao_0420/article/details/80255593 使用:console.log(addDate("2018-6- ...

  3. python的globals()

    以字典的形式返回当前位置的全局变量

  4. window下git的下载

    window下git的下载window下git的下载window下git的下载window下git的下载 https://git-scm.com/download/win https://git-sc ...

  5. C语言strcasecmp()函数:判断字符串是否相等(忽略大小写)

    头文件:#include <string.h> 定义函数:int strcasecmp (const char *s1, const char *s2); 函数说明:strcasecmp( ...

  6. 【Linux】-NO.8.Linux.4.Command.1.001-【Common Command】-

    1.0.0 Summary Tittle:[Linux]-NO.8.Linux.4.Command.1.001-[Common Command]- Style:Linux Series:Command ...

  7. python3编写发送四种http请求的脚本

    python3编写发送http请求的脚本 使用requests包: http://docs.python-requests.org/zh_CN/latest/user/quickstart.html ...

  8. [LeetCode] 374. Guess Number Higher or Lower_Easy tag: Binary Search

    We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to gues ...

  9. [Java in NetBeans] Lesson 01. Java Programming Basics

    这个课程的参考视频在youtube. 主要学到的知识点有: Create new project, choose Java Application. one .jar file/ package(.j ...

  10. GBDT调参总结

    一.GBDT类库弱学习器参数 二.回归 数据集:已知用户的30个特征,预测用户的信用值 from sklearn.ensemble import GradientBoostingRegressor f ...