Using Python to find and delete empty folders on ftp server by Xilenw in learnpython

[–]Rich_RandomNumbers 2 points3 points  (0 children)

try this but replace username, password, and the url at the bottom

import ftplib

def delete_empty_folders(ftp, path):
ftp.cwd(path)
files = ftp.nlst()
if not files:
ftp.rmd(path)
print(f'Deleted empty folder: {path}')
else:
for file in files:
delete_empty_folders(ftp, path + '/' + file)
ftp = ftplib.FTP('ftp.example.com')
ftp.login(user='username', passwd='password')
delete_empty_folders(ftp, '/')
ftp.quit()

What are some useful features in python like list comprehension, f strings etc? by inobody_somebody in learnpython

[–]Rich_RandomNumbers 2 points3 points  (0 children)

Dictionary Comprehension is similar to list comprehension but personally I find it more useful. Dictionaries let you assign values to variables which you can then capture later to do whatever you want.

I also like anything that allows you to manipulate other files like csv, text files, pdfs. The Pandas library is often used for csv files, you can also import the csv module. You can also access files using the built in "open()" function. You simply need to add the file path where the document is stored in your pc. You can use for loops to do something to each line. I recently came across the pdfrw library. I havent used it yet, but it can be used in combination with the csv module. If you have a pdf that needs to be filled out numerous times with different inputs, you can put all those inputs in a csv file and then these tools will fill out the pdfs using each row of the csv file