Skip to content

Instantly share code, notes, and snippets.

@gitleej
Created September 10, 2018 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gitleej/853c6eec9e449ea1087f3287eb4a7098 to your computer and use it in GitHub Desktop.
Save gitleej/853c6eec9e449ea1087f3287eb4a7098 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 10 10:07:16 2018
@author: Administrator
"""
# 导入必要的包
import os
import pandas as pd
PATH = ".\\"
fileCount = 0
dirCount = 0
for x, _, _ in os.walk(os.path.dirname(PATH)):
if len(x) != 0:
fileCount = 0
dirCount = 0
paths = os.listdir(x)
for path in paths:
path = os.path.sep.join([x, path])
if os.path.isdir(path):
dirCount += 1
elif os.path.isfile(path):
fileCount += 1
print(x)
print("\tfiles: {}".format(fileCount))
print("\tdirs: {}".format(dirCount))
fileList=[]
for root, dirs, files in os.walk(PATH):
fileList.append([])
fileList[-1].append(root)
for file in files:
fileList[-1].append(file)
csvFileList = pd.DataFrame(fileList)
csvFileList.to_csv("filelist.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment