首页 > 解决方案 > Google colab "glob.glob" 为什么找不到我的 1456 文件?

问题描述

为什么找不到我的 1456 文件?

import pandas as pd  
import numpy as np
import sys
# uncommen the next row to install altair
# !{sys.executable} -m pip install altair vega_datasets
import altair as alt
import os 
import copy
import glob
import matplotlib.pyplot as plt
from google.colab import drive
drive.mount('/content/drive')
path_files = r"/content/drive/MyDrive/BigData"
# All files ending with .txt
files = glob.glob("{}\*.txt".format(path_files))
print("Nombre de fichiers: {}".format(len(files)))

结果文件数:0

它必须找到1456个文件

标签: pythonpathgoogle-colaboratory

解决方案


解决方案是:

所有以 .txt 结尾的文件

files = glob.glob(f"/content/gdrive/...../*.txt")
print("Nombre de fichiers: {}".format(len(files)))

推荐阅读