-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tree method to display tree-like structure of the filesystem #1750
base: master
Are you sure you want to change the base?
Conversation
>>> fs.tree(path='/start/folder', display_size=True) /start/folder ├── folder1 │ ├── file1.txt (1.234MB) │ └── file2.txt (0.567MB) └── folder2 └── file3.txt (2.345MB)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nice addition!
I have some suggestions, and this code could really use a test, probably using memoryFS (fixture m
).
@martindurant I went along with your proposals. This can be used as follows: from fsspec import filesystem
fs = filesystem('ftp', host='test.rebex.net', user='demo', password='password')
tree = fs.tree(display_size=True, recursion_limit=3, indent_size=8, max_display=10)
print(tree)
/
├────── pub (1 subfolder)
│ └────── example (16 files)
│ ├────── KeyGenerator.png (35.81 kb)
│ ├────── KeyGeneratorSmall.png (23.47 kb)
│ ├────── ResumableTransfer.png (11.28 kb)
│ ├────── WinFormClient.png (78.12 kb)
│ ├────── WinFormClientSmall.png (17.49 kb)
│ ├────── imap-console-client.png (18.71 kb)
│ ├────── mail-editor.png (16.08 kb)
│ ├────── mail-send-winforms.png (34.58 kb)
│ ├────── mime-explorer.png (47.86 kb)
│ ├────── pocketftp.png (56.66 kb)
│ └────── 6 more item(s) not displayed.
└────── readme.txt (379B) Or: fs = filesystem('gs')
tree = fs.tree(path='gs://gcp-public-data-arco-era5', display_size=True, recursion_limit=2, indent_size=8, max_display=5)
print(tree)
gs://gcp-public-data-arco-era5
├────── ar (19 subfolders)
│ ├────── 1959-2022-1h-240x121_equiangular_with_poles_conservative.zarr (3 files, 35 subfolders)
│ ├────── 1959-2022-1h-360x181_equiangular_with_poles_conservative.zarr (3 files, 35 subfolders)
│ ├────── 1959-2022-6h-128x64_equiangular_conservative.zarr (3 files, 42 subfolders)
│ ├────── 1959-2022-6h-128x64_equiangular_with_poles_conservative.zarr (3 files, 42 subfolders)
│ ├────── 1959-2022-6h-1440x721.zarr (3 files, 42 subfolders)
│ └────── 14 more item(s) not displayed.
├────── co (10 subfolders)
│ ├────── model-level-moisture.zarr (3 files, 13 subfolders)
│ ├────── model-level-moisture.zarr-v2 (3 files, 13 subfolders)
│ ├────── model-level-wind.zarr (3 files, 8 subfolders)
│ ├────── model-level-wind.zarr-v2 (3 files, 8 subfolders)
│ ├────── single-level-forecast.zarr (3 files, 28 subfolders)
│ └────── 5 more item(s) not displayed.
└────── raw (4 subfolders)
├────── ERA5GRIB (1 subfolder)
├────── date-variable-pressure_level (85 subfolders)
├────── date-variable-single_level (85 subfolders)
└────── date-variable-static (1 subfolder) Is this what you had in mind ? |
Looks good! |
It would still be nice to create some minimal test for this, based on files in memoryFS |
(please run |
/start/folder
├── folder1
│ ├── file1.txt (1.234MB)
│ └── file2.txt (0.567MB)
└── folder2
└── file3.txt (2.345MB)