zoukankan      html  css  js  c++  java
  • 文件、文件夹操作(I)

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

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

    1 let manager = FileManager.default
    2         let urlForDocument = manager.urls(for: .documentDirectory, in:.userDomainMask)
    3         let url = urlForDocument[0] as URL
    4         print("---------->(url)")
    View Code

    打印结果:

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

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

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

    打印结果:

    enumeratorAtPath: Optional([])

    参考:文件夹操作

     

  • 相关阅读:
    rocketmq的linux搭建环境
    linux调用本地shell脚本
    第二课
    第一课
    有意思的dos攻击
    信息收集
    url跳转挖掘
    Drozer之android_app分析实战
    缓存中毒
    随便写写
  • 原文地址:https://www.cnblogs.com/EchoHG/p/9064880.html
Copyright © 2011-2022 走看看