zoukankan      html  css  js  c++  java
  • 保存linux下当前目录下所有文件的相对路径

    方法一:

    在系统可以上网的条件下:

    1、安装工具:tree;

    2、在终端输入

    tree -f -i > file_list_path

      file_list_path 文件内容即为当前目录下所有文件的相对路径

    方法二:

    在系统无法上网的情况下:

    1、编写python脚本

    import os
    root = os.getcwd()
    
    
    def file_name(file_dir):
        with open(root+'_pwd', 'w', encoding='utf-8') as f:  # 使用with open()新建对象f
            for root_dir, dirs, files in os.walk(file_dir):
                for file_names in files:
                    print('.' + root_dir[len(root):] + '/' + file_names)
                    file_path = '.' + root_dir[len(root):] + '/' + file_names
                    f.write(file_path + '
    ')  # 写入数据,文件保存在上面指定的目录,加
    为了换行更方便阅读
    
        f.close()  # 关闭文件
    
    
    file_name(root)

    2、在需要查看的目录下运行python 脚本即可

  • 相关阅读:
    学习进度十二
    学习情况记录 11
    2020寒假 13
    学习情况记录 10
    学习情况记录 09
    2020寒假 12
    学习情况记录 08
    2020寒假 11
    学习情况记录 07
    2020寒假 10
  • 原文地址:https://www.cnblogs.com/dashawntang/p/12180745.html
Copyright © 2011-2022 走看看