I don't understand why my first for loop works as intended (prints all the folders from the cwd) but my second for loop (which should do the same but in an updated directory) doesn't.
If i print "stuff" and "stuff_t" they both correctly return the list of all the elements in the given directory. Here's the code (dirname is the name of a folder in the starting directory):
import os
import os.path
def es68(dirname):
cwd = os.getcwd()
stuff = os.listdir(cwd)
for i in stuff:
if os.path.isdir(i) == True:
print(i)
t = os.path.join(cwd, dirname)
stuff_t = os.listdir(t)
for i in stuff_t:
if os.path.isdir(i) == True:
print(i)
stuff_t = os.listdir(t)returns only the relative paths. The reason it does not work in the second loop is because you are not in the cwd anymore. To make your code work, change the following loop: