Spaces:
Running
Running
// Function to fetch and display the contents of a folder | |
function listFolderContents() { | |
const folderContents = document.getElementById('folder-contents'); | |
// Replace 'your-folder-path/' with the path to your folder | |
const folderPath = 'spidey/'; | |
// Fetch a list of files and subfolders in the folder | |
fetch(folderPath) | |
.then(response => response.text()) | |
.then(data => { | |
const items = data.split('\n').filter(item => item.trim() !== ''); | |
// Create an unordered list to display the contents | |
const ul = document.createElement('ul'); | |
items.forEach(item => { | |
const li = document.createElement('li'); | |
li.textContent = item; | |
ul.appendChild(li); | |
}); | |
folderContents.appendChild(ul); | |
}) | |
.catch(error => console.error('Error loading folder contents:', error)); | |
} | |
// Call the function to list folder contents when the page loads | |
window.onload = listFolderContents; | |