xxxxxxxxxx
import shutil
from fpdf import FPDF
import os
from os import listdir
from os.path import isfile, join
import glob
import re
print("Paste in the directory path :")
s=input()
all_dir=glob.glob(s)
print(all_dir)
xxxxxxxxxx
import os
arr = os.listdir()
print(arr)
>>> ['$RECYCLE.BIN', 'work.txt', '3ebooks.txt', 'documents']
xxxxxxxxxx
In MS Windows it works like this:
1. Hold the "Shift" key, right-click the folder containing the files and select "Open Command Window Here."
2. Type "dir /b > filenames.txt" (without quotation marks) in the Command Window. Press "Enter."
3. Inside the folder there should now be a file filenames.txt containing names of all the files etc. inside this folder.
4. Copy and paste this file list into your Word document.
xxxxxxxxxx
import os
arr = next(os.walk('.'))[2]
print(arr)
>>> ['5bs_Turismo1.pdf', '5bs_Turismo1.pptx', 'esperienza.txt']
xxxxxxxxxx
import os
foldertoscan = input("Enter File/Folder: ")
ALLfiles = []
ALLfolders = []
def getFiles(folder):
global ALLfiles, ALLfolders
if os.path.isfile(folder):
ALLfiles.append(folder)
elif os.path.isdir(folder):
ALLfolders.append(folder)
for file in os.listdir(folder):
file = folder+"\\"+file
getFiles(file)
else:
print("Invalid file/directory")
getFiles(foldertoscan)
print(ALLfiles)
xxxxxxxxxx
var fs = require('fs');
var files = fs.readdirSync('/assets/photos/');
List all files & directories in the current directory
xxxxxxxxxx
ls -la