import os
mypath = '/Users/ken/Desktop/myFolder/'
for folderName, subfolders, filenames in os.walk(mypath):
print('The current folder is ' + folderName)
for subfolder in subfolders:
print('SUBFOLDER OF ' + folderName + ': ' + subfolder)
for filename in filenames:
print('FILE INSIDE ' + folderName + ': '+ filename)
print('')
Hi guys, somehow my code above, which utilises the os.walk() function, does not print out anything at all. I'm pretty sure this is the correct way to state the path to my folder (which is indeed located on my desktop). However, when I tried to use the path '/Users/ken/' it does return and print out a whole bunch of files/folders. I'm not sure why with the above path (adding the /Desktop/myFolder) does not work. I am using a MacBook btw
Edit: I realised something else odd - in my home directory I have a Downloads folder as well which stores all my recent downloads from online. Somehow when I set the path as /Users/ken/Downloads
it prints nothing out as well. It does work for any other /Users/ken/anyfolder
contained in my home directory though but I'm not sure why it doesn't access my folders on my Desktop
Edit: It works when I tried it on another text editor (PyCharm). Previously I tried it on mu-editor. Idk why it doesn't work