I have a root directory with two subdirectories, cat and dog. In there, I have a few text files. I'm trying to iterate through all the subdirectories and print the file names. Below is the code:
import glob
path = '/Users/msmacbook/Desktop/test/'
for x in glob.glob(path+'**/*'):
print(x.replace(path, ""))
And here is the output:
cat/cat1
cat/cat2
cat/cat3
dog/dog1
dog/dog2
dog/dog3
Where cat and dog are the subdirectories and cat1..etc, dog1..etc are the files.
How do I only print/retrieve the file names? I want the desired output to be
cat1
cat2
cat3
dog1
dog2
dog3