Skip to content

Commit 302944f

Browse files
committed
Implement listdir_meta in LocalFileSystem
1 parent 354f8fb commit 302944f

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

DPF/filesystems/localfilesystem.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import os
22
import io
3+
from datetime import datetime
34
from typing import Union, List, Optional, Tuple, Iterable
45

5-
from .filesystem import FileSystem
6+
from .filesystem import FileSystem, FileData
67

78

89
class LocalFileSystem(FileSystem):
@@ -44,6 +45,18 @@ def listdir(
4445
files = [folder_path + f for f in files]
4546
return files
4647

48+
def listdir_meta(self, folder_path: str) -> List[FileData]:
49+
folder_path = folder_path.rstrip("/") + "/"
50+
results = []
51+
for fd in os.scandir(folder_path):
52+
path = fd.path
53+
type_ = 'directory' if fd.is_dir() else 'file'
54+
stats = fd.stat()
55+
size = stats.st_size
56+
last_modified = datetime.fromtimestamp(stats.st_mtime)
57+
results.append(FileData(path, type_, last_modified, size))
58+
return results
59+
4760
def mkdir(self, folder_path: str) -> None:
4861
folder_path = folder_path.rstrip("/") + "/"
4962
os.makedirs(folder_path, exist_ok=True)

0 commit comments

Comments
 (0)